DATEDIFF( )

This MySQL function returns the number of days of difference between the two dates given.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

DATEDIFF(date, date)

Explanation

This function returns the number of days of difference between the two dates given. Although a parameter may be given in date and time format, only the dates are used for determining the difference. This function is available as of version 4.1.1 of MySQL.

Examples

SELECT CURDATE( ) AS Today,
DATEDIFF('2008-12-25', NOW( ))
AS 'Days to Christmas';

+------------+-------------------+
| Today      | Days to Christmas |
+------------+-------------------+
| 2008-03-14 |               286 |
+------------+-------------------+