How to get the previous day with MySQL CURDATE()?


Let us first get the current date using CURDATE(). The current date is as follows −

mysql> select CURDATE();
+------------+
| CURDATE()  |
+------------+
| 2019-06-09 |
+------------+
1 row in set (0.00 sec)

Let us first create a table −

mysql> create table DemoTable
   -> (
   -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> ShippingDate date
   -> );
Query OK, 0 rows affected (0.63 sec)

Insert some records in the table using insert command. While inserting, we have used date_sub to get the previous day −

mysql> insert into DemoTable(ShippingDate) values(date_sub(CURDATE(), interval 1 day));
Query OK, 1 row affected (0.22 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

Output

+----+--------------+
| Id | ShippingDate |
+----+--------------+
| 1 | 2019-06-08    |
+----+--------------+
1 row in set (0.00 sec)

Updated on: 30-Jul-2019

231 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements