Display dates after NOW() + 10 days from a MySQL table?


You can use DATE_ADD() function with where clause for this. Let us first create a table −

mysql> create table DemoTable
   (
   ShippingDate date
   );
Query OK, 0 rows affected (0.54 sec)

Note : The current date and time is as follows, we found using NOW() −

mysql> select now();
+-----------------------+
| now()                 |
+-----------------------+
| 2019-06-04 20 :43 :57 |
+-----------------------+
1 row in set (0.00 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('2019-06-16');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable values('2019-05-31');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable values('2019-05-24');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable values('2019-06-24');
Query OK, 1 row affected (0.17 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

Output

+--------------+
| ShippingDate |
+--------------+
| 2019-06-16   |
| 2019-05-31   |
| 2019-05-24   |
| 2019-06-24   |
+--------------+
4 rows in set (0.00 sec)

Following is the query to display dates after NOW() + 10 days −

mysql> select *from DemoTable where ShippingDate > DATE_ADD(now(), INTERVAL 10 DAY);

Output

+--------------+
| ShippingDate |
+--------------+
| 2019-06-16   |
| 2019-06-24   |
+--------------+
2 rows in set (0.00 sec)
raja
Published on 13-Jun-2019 11:57:59
Advertisements