[MySQL] Get the number of days between two dates

Created on November 30, 2026

DATEDIFF subtracts the second date from the first and returns the difference in days.

select datediff("2022-07-20", "2022-07-25");

Output

+--------------------------------------+
| datediff("2022-07-20", "2022-07-25") |
+--------------------------------------+
|                                   -5 |
+--------------------------------------+
1 row in set (0.00 sec)
MySQL