How to compare two dates in MySQL

In this MySQL post, we will see how to compare two dates in MySQL.

To compare two dates in MySQL, we will use DATEDIFF function of MySQL. It will return the difference of number of days between two dates.

Lets understand how we can use DATEDIFF function in MySQL by taking an example.

Compare Two dates in MySQL Example – DATEDIFF Example

SELECT DATEDIFF(“2023-12-19”, “2023-12-10”);

mysql> SELECT DATEDIFF("2023-12-19", "2023-12-10");
| DATEDIFF("2023-12-19", "2023-12-10") |
|                                    9 |
1 row in set (0.45 sec)

We have two dates "2023-12-19" and "2023-12-10", When we used DATEDIFF function to compare these two

Scroll to Top