DATEDIFF
Calculates the day difference between two dates.
Overview
MySQL DATEDIFF(date1, date2) returns the day difference date1 minus date2 and uses only the date parts of its arguments. Argument order controls the sign; use an appropriate time function when time zones or sub-day precision matter. Fixed dates keep this tutorial result reproducible.
Basic syntax
SELECT DATEDIFF('2026-02-01', '2026-01-01') AS days;
Examples
DATEDIFF example
Calculate 2026-02-01 minus 2026-01-01 and verify the positive result and argument order.
Run result
| days |
|---|
| 31 |
Common issues
Yes. In MySQL it returns the first date minus the second, so reversing arguments changes the sign.
MySQL DATEDIFF compares date parts only; use TIMESTAMPDIFF when you need finer units.
No. Function names, argument order, and result units vary, so verify the target database.
Tags
Was this explanation clear?
Thanks. This feedback will inform the next content review.