Selecting rows that are older than current date in MySQL?



Let’s say the current date is 2019-08-03. Now, we will see an example and create a table −

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

Insert some records in the table using insert command −

mysql> insert into DemoTable840 values('2019-08-9'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable840 values('2019-07-5'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable840 values('2019-08-10'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable840 values('2019-07-13'); Query OK, 1 row affected (0.10 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable840;

This will produce the following output −

+-----------------------+ | DueDate             | +-----------------------+ | 2019-08-09 00 −00 −00 | | 2019-07-05 00 −00 −00 | | 2019-08-10 00 −00 −00 | | 2019-07-13 00 −00 −00 | +-----------------------+ 4 rows in set (0.00 sec)

Following is the query to select rows older than the current date in MySQL −

mysql> select *from DemoTable840 where DueDate < NOW();

This will produce the following output −

+-----------------------+ | DueDate             | +-----------------------+ | 2019-07-05 00 −00 −00 | | 2019-07-13 00 −00 −00 | +-----------------------+ 2 rows in set (0.00 sec)
Updated on: 2019-09-03T14:41:53+05:30

877 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements