Let’s say the current date is 2019-09-14 8 :50 :10. Now, we want records from 00 :00 to 2019-09-14 8 :50 :10. Let us now see an example and create a table −
mysql> create table DemoTable ( DueDate datetime ); Query OK, 0 rows affected (0.66 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-09-14'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('2019-09-14 8 :00 :10'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2019-09-14 8 :44 :00'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2019-09-14 12 :10 :00'); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------------------+ | DueDate | +---------------------+ |2019-09-14 00:00 :00 | |2019-09-14 08 :00 :10| |2019-09-14 08 :44 :00| |2019-09-14 12 :10 :00| +---------------------+ 4 rows in set (0.00 sec)
Following is the query to select date from 00 :00 to today’s date −
mysql> select *from DemoTable where DueDate > DATE(NOW()) and DueDate < NOW();
This will produce the following output −
+---------------------+ | DueDate | +---------------------+ |2019-09-14 08 :00 :10| |2019-09-14 08 :44 :00| +---------------------+ 2 rows in set (0.00 sec)