Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

MySQL DATEDIFF() function


May 15, 2021 MySQL


Table of contents


MySQL DATEDIFF() function


MySQL DATEDIFF() function MySQL Date function

Definitions and usages

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

Grammar

DATEDIFF(date1,date2)

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

Note: Only the date portion of the value participates in the calculation.


Instance

Here's the SELECT statement:

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

The result is as follows:

DiffDate
1

Instance

Here's the SELECT statement:

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

The result is as follows:

DiffDate
-1


MySQL DATEDIFF() function MySQL Date function