MySQL query to retrieve current date from a list of dates


Let’s say the current date is −

2019-07-22

Let us first create a table −

mysql> create table DemoTable705 (ShippingDate datetime);
Query OK, 0 rows affected (0.67 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable705 values('2019-01-21 23:59:00');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable705 values('2019-07-22 00:00:30');
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable705 values('2019-07-21 12:01:30');
Query OK, 1 row affected (0.44 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable705;

This will produce the following output -

+---------------------+
| ShippingDate        |
+---------------------+
| 2019-01-21 23:59:00 |
| 2019-07-22 00:00:30 |
| 2019-07-21 12:01:30 |
+---------------------+
3 rows in set (0.00 sec)

Following is the query to retrieve current date from a list of dates −

mysql> select *from DemoTable705 where date(ShippingDate)=CURDATE();

This will produce the following output -

+---------------------+
| ShippingDate        |
+---------------------+
| 2019-07-22 00:00:30 |
+---------------------+
1 row in set (0.00 sec)

Updated on: 21-Aug-2019

187 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements