Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

MySQL DATEDIFF() function

MySQL DATEDIFF() function


SQL Dates MySQL Date Functions


Definition and Usage

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

Syntax

DATEDIFF(date1,date2)

The date1 and date2 parameters are valid date or date/time expressions.

**Note:** Only the date part of the values is used in the calculation.


Example

The following is the SELECT statement:

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

The result is as follows:

DiffDate
1

Example

The following is the SELECT statement:

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

The result is as follows:

DiffDate
-1

SQL Dates MySQL Date Functions