How to select rows in MySQL that are >= 1 DAY from the current date?


To get data greater than equal to 1 day from the current date, use the concept of INTERVAL in MySQL.

The current date is as follows −

mysql> select curdate();
+------------+
| curdate()  |
+------------+
| 2019-11-29 |
+------------+
1 row in set (0.00 sec)

We will first create a table −

mysql> create table DemoTable1806
     (
     DueDate datetime
     );
Query OK, 0 rows affected (0.00 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1806 values('2019-11-28');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1806 values('2019-11-29');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1806 values('2019-11-30');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1806 values('2019-11-25');
Query OK, 1 row affected (0.00 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1806;

This will produce the following output −

+---------------------+
| DueDate             |
+---------------------+
| 2019-11-28 00:00:00 |
| 2019-11-29 00:00:00 |
| 2019-11-30 00:00:00 |
| 2019-11-25 00:00:00 |
+---------------------+
4 rows in set (0.00 sec)

Here is the query to select rows which is >=1 day from the current date

mysql> select * from DemoTable1806 where DueDate >= now() - INTERVAL 1 DAY;

This will produce the following output −

+---------------------+
| DueDate             |
+---------------------+
| 2019-11-29 00:00:00 |
| 2019-11-30 00:00:00 |
+---------------------+
2 rows in set (0.00 sec)

Updated on: 24-Dec-2019

679 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements