MySQL DATEDIFF Function Explained: Calculate Date Differences
The DATEDIFF function in MySQL is used to calculate the difference between two dates in days. It returns the number of days between the two dates.
The syntax of this function is as follows:
DATEDIFF(date1, date2)
The function compares two date parameters, date1 must be a later date and date2 must be an earlier date. It returns the difference in days between date1 and date2.
For example, if you want to calculate the number of days between October 1, 2019 and October 5, 2019, you can use the following query:
SELECT DATEDIFF(‘2019-10-05’, ‘2019-10-01’);
The result will be 4, indicating a 4-day difference between these two dates.