![Logo loader icon](https://w3codegenerator.com/img/logo-f2.png)
How to get yesterday's date in MySQL ?
How can i get yesterday's date in MySQL.
In this tutorial you will learn how you can get the yesterday date using inbuilt SQL functions and you can also create own function and call it to get the yesterday's date.
Please execute delimiter //
statement in MySQL shell before creating function in MySQL.
Run the below SQL statement to create function -
create function getYesterdayDate()
returns date
begin
return adddate(current_date(), interval -1 day);
end //
Call function using below statement
select getYesterdayDate() //
Output :
mysql> select getYesterdayDate() // +--------------------+ | getYesterdayDate() | +--------------------+ | 2024-02-20 | +--------------------+ 1 row in set (0.00 sec)
-
You can use DATE_SUB function to get the yesterday's date in MySQL
SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY) AS yesterday_date;
The SQL statement
SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY) AS yesterday_date;
retrieves the date of yesterday from the current date. It uses theCURDATE()
function to get the current date and theDATE_SUB()
function to subtract one day from it usingINTERVAL 1 DAY
.
Related Queries
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Sql
- Create Employee table in MySQL
- Get comma separated ids from table using MySQL
- How to drop function in MySQL ?
- ERROR 3780 (HY000): Referencing column 'order_id' and referenced column 'id' in foreign key constraint 'order_items_ibfk_1' are incompatible.
- Get create table Query from existing table in phpMyAdmin
- Create Index in MySQL with example
- SQLSTATE[01000]: Warning: 1265 Data truncated for column 'visibility' at row 1
- How to create function in MySQL ?
- Get full name of a person in SQL using function
- Clear the terminal screen in MySQL within the Windows powershell
- Cannot drop index 'fk_role_id': needed in a foreign key constraint
- Get data in random order with limit from table using mysql
- Difference between SQL and NoSQL databases
- Self join in mysql employee manager example
- SQL query to delete records older than 6 months
- 1553 Cannot drop index 'posts_user_id_foreign': needed in a foreign key constraint
- Check constraint in MySQL
- Drop foreign id column (user_id) in MySQL
- MySQL create procedure example
- How to check column exists or not in table using MySQL
- How to Rename column name in MySql ?
- Change existing MySQL table column id to autoincrement
- How to check the MySQL version
- How to retrieve data from two tables with one SQL statement
- Get number of connections being used by a specific user in MySQL