- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the previous day with MySQL CURDATE()?
152 Lectures 16 hours
87 Lectures 5.5 hours
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;
+----+--------------+ | Id | ShippingDate | +----+--------------+ | 1 | 2019-06-08 | +----+--------------+ 1 row in set (0.00 sec)
- How to get last day of the previous month in MySQL?
- How to get the first day of the previous month in MySQL?
- Get all MySQL records from the previous day (yesterday)?
- How to use CONTAINS() with CURDATE in MySQL?
- C# program to display the previous day
- Java Program to display previous day from GregorianCalender
- How to get the first day of next month in MySQL?
- How to get last day of the current month in MySQL?
- How to get last day of the next month in MySQL?
- How to get the first day of the current month in MySQL?
- How to get day name from timestamp in MySQL?
- CURDATE () vs NOW() in MySQL
- Change the curdate() (current date) format in MySQL
- How can I use INTERVAL keyword with MySQL NOW() and CURDATE() functions?
- Get day name for the corresponding date in MySQL?