- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Condition to check for due date and current date records in MySQL where clause
To check for such conditions, use IF() in MySQL.
Let us create a table −
Example
mysql> create table demo89 -> ( -> duedate date -> ); Query OK, 0 rows affected (0.78
Insert some records into the table with the help of insert command −
Example
mysql> insert into demo89 values('2020-01-10'); Query OK, 1 row affected (0.55 mysql> insert into demo89 values(null); Query OK, 1 row affected (0.13 mysql> insert into demo89 values('2020-11-29'); Query OK, 1 row affected (0.15 mysql> insert into demo89 values('2019-11-29'); Query OK, 1 row affected (0.09
Display records from the table using select statement −
Example
mysql> select *from demo89;
This will produce the following output −
Output
+------------+
| duedate |+------------+
| 2020-01-10 || NULL |
| 2020-11-29 || 2019-11-29 |
+------------+4 rows in set (0.00 sec)
Following is the query to check for due date and current date records −
Example
mysql> select if (duedate is null -> or duedate < curdate(),'Wrong Date',duedate) as Result -> from demo89;
This will produce the following output −
Output
+------------+
| Result |+------------+
| Wrong Date || Wrong Date |
| 2020-11-29 || Wrong Date |
+------------+4 rows in set (0.00 sec)
- Related Articles
- Select a column if condition is met in MySQL to fetch records from current date and current date + 1
- How to get the difference between date records and the current date in MySQL?
- Comparison of varchar date records from the current date in MySQL
- How to use MySQL Date functions with WHERE clause?
- MySQL query to get the current date records wherein one of the columns displays current date
- Calling NOW() function to fetch current date records in MySQL?
- Find the difference between current date and the date records from a MySQL table
- How to update column values with date records and set 1 for corresponding records before the current date in SQL
- Grab where current date and the day before with MySQL?
- Fastest way to search for a date from the date records in MySQL
- Display all records ignoring the current date record in MySQL
- MySQL query to find the date records wherein the current date and time is in between the JoiningDate and RelievingDate
- MySQL DATE function to return the difference between current date and joining date
- MySQL query to fetch date records greater than the current date after adding days with INTERVAL?
- MySQL time period query to fetch date records from interval of 14 weeks from current date?

Advertisements