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
- MySQL create procedure example
- SQL query to delete all rows older than 30 days
- How to get a list of MySQL views?
- Cannot drop index 'fk_role_id': needed in a foreign key constraint
- How to get the list of all constraints in MySQL database
- Get full name of a person in SQL using function
- How to retrieve data from two tables with one SQL statement
- Get comma separated ids from table using MySQL
- Change existing MySQL table column id to autoincrement
- Get data in random order with limit from table using mysql
- ERROR 3780 (HY000): Referencing column 'order_id' and referenced column 'id' in foreign key constraint 'order_items_ibfk_1' are incompatible.
- SQL query to delete records older than 6 months
- How to Rename column name in MySql ?
- 1553 Cannot drop index 'posts_user_id_foreign': needed in a foreign key constraint
- Insert multiple rows in a single MySQL query
- How to create function in MySQL ?
- Get create table Query from existing table in phpMyAdmin
- How to create a new table from existing table in SQL
- SQLSTATE[01000]: Warning: 1265 Data truncated for column 'visibility' at row 1
- Clear the terminal screen in MySQL within the Windows powershell
- Check constraint in MySQL
- How to check column exists or not in table using MySQL
- How to show database tables in mysql using command line
- Create column after a column in existing table using query in MySQL
- Create Index in MySQL with example