MySQL DATEDIFF function is one of the Date Function, which is used to find the difference between two dates and returns the number of days.
In this article, we will show you, How to use this MySQL Date diff function to find the difference between dates with example.
MySQL DATEDIFF Syntax
The basic syntax of the DATEDIFF() Function in MySQL is as shown below:
This function subtracts Date Expression2 from Expression1 (Expression1 – Expression2) and returns the value. It will not consider the Time value into the consideration.
MySQL DATEDIFF function Example
The below shown queries helps you understand the use of this MySQL Date Difference function. Here, we are finding the difference in total number of days between Date and time expression.
SELECT DATEDIFF('2019-02-28', '2019-01-01');
SELECT DATEDIFF('2019-02-28', '2019-12-31');
SELECT DATEDIFF('2019-02-28 12:11:22', '2019-12-31');
SELECT NOW(), DATEDIFF(NOW(), '2018-12-31');
SELECT CURDATE(), DATEDIFF(CURDATE(), '2017-12-31');
SELECT CURRENT_TIMESTAMP, DATEDIFF(CURRENT_TIMESTAMP, '2018-01-31');
MySQL Date Difference Example 2
In this example, we will show you, how to use this MySQL Date Difference function on a table. Here, we are finding the difference between current date and Employees Hire date.
DATEDIFF(NOW(), HireDate) AS 'DATEDIFF Example'
FROM `MySQL Tutorial`.customer;
Thank You for Visiting Our Blog