MySQL get the difference between two dates; In this tutorial, i am going to show you how to find or get difference between two dates in days using the MySQL datediff() function.
How to Find the Number of Days Between Two Dates in MySQL
The MySQL DATEDIFF function returns the difference in days between two date values.
Syntax of MySQL DATEDIFF Function
The MySQL DATEDIFF syntax is:
DATEDIFF( date1, date2 )
Parameters of MySQL DATEDIFF function
- date1 A date/datetime value
- date2 A date/datetime value
Examples 1 – To Find/Calculate Days Between Two Dates in Days
To find the number of days between two dates in mysql; as follows:
SELECT DATEDIFF('2019-10-10', '2019-02-15'); Output: 237
Examples 2 – To Calculate Days Between Two Dates in Days
Let’s see the following example to calculate days between two dates in days; as follows:
SELECT DATEDIFF('2019-5-10 11:41:14', '2019-02-15 12:10:08'); Output: 84
In this tutorial, you have learned how to use MySQL DATEDIFF function to calculate the number of days between two date values.