The following describes the MySQL DATEDIFF () function, which is used to return the number of days between two dates. It is one of the most common MySQL functions and deserves further research.
Definition and usage
The MySQL 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 value is involved in calculation.
Instance
Example 1
Use the following SELECT statement:
Select datediff ('2014-12-30 ', '2014-12-29') AS DiffDate
Result:
DiffDate
1
Example 2
Use the following SELECT statement:
Select datediff ('2014-12-29 ', '2014-12-30') AS DiffDate
Result:
DiffDate
-1
The preceding section describes the MySQL DATEDIFF () syntax.
MySQL Date and Time Extract function Introduction
MySQL date functions
Provides you with an in-depth understanding of the MYSQL Cast function.
MySQL string processing function concat_ws ()
MySQL string segmentation and concatenation statements