DATEDIFF() is a very useful function which tells you the difference in days between to dates.

Please note that only the year,month and day parts of the date are used. Hour, minutes and seconds will be ignored.

Also put the later date first to get a plus value, please see the second example to see the reverse.

Example

SELECT DATEDIFF('1999-02-05','1999-02-03')

Returns

2

 

Example

SELECT DATEDIFF('1999-02-03','1999-02-05')

Returns

-2