- 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
How to check if a date has passed in MySQL?
Let us first create a table −
mysql> create table DemoTable1340 -> ( -> Deadline date -> ); Query OK, 0 rows affected (0.43 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1340 values('2019-09-18'); Query OK, 1 row affected (0.52 sec) mysql> insert into DemoTable1340 values('2019-09-23'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1340 values('2018-12-24'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1340 values('2016-11-01'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1340 values('2019-09-28'); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1340;
This will produce the following output −
+------------+ | Deadline | +------------+ | 2019-09-18 | | 2019-09-23 | | 2018-12-24 | | 2016-11-01 | | 2019-09-28 | +------------+ 5 rows in set (0.00 sec)
We should know the current date as well. The current date is as follows −
mysql> select curdate(); +------------+ | curdate() | +------------+ | 2019-09-21 | +------------+ 1 row in set (0.00 sec)
Here is the query to check if a date has passed −
mysql> select * from DemoTable1340 where Deadline >= curdate();
This will produce the following output −
+------------+ | Deadline | +------------+ | 2019-09-23 | | 2019-09-28 | +------------+ 2 rows in set (0.00 sec)
Advertisements