SQLPathLab
Date and Time · Basic

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

result
days
31

Common issues

Does DATEDIFF argument order affect the sign?

Yes. In MySQL it returns the first date minus the second, so reversing arguments changes the sign.

Does DATEDIFF include time-of-day?

MySQL DATEDIFF compares date parts only; use TIMESTAMPDIFF when you need finer units.

Is DATEDIFF portable across databases?

No. Function names, argument order, and result units vary, so verify the target database.

Tags

CommonDate & time

Was this explanation clear?