MySQL DATEDIFF() Function

Definition and Usage

The DATEDIFF() function returns the number of days between two dates.

Syntax

DATEDIFF(date1,date2)

date1 and date2 The parameter is a valid date or date/time expression.

Note:Only the date part of the value is involved in the calculation.

Instance

Example 1

Use the following SELECT statement:

SELECT DATEDIFF('2008-12-30','2008-12-29') AS DiffDate

Result:

DiffDate
1

Example 2

Use the following SELECT statement:

SELECT DATEDIFF('2008-12-29','2008-12-30') AS DiffDate

Result:

DiffDate
-1