- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements