How can I calculate full 24hour days between two specified dates in MySQL?


In DATEDIFF() function only the date parts of the values are used in calculation hence we can use TIMESTAMPDIFF() function to calculate full 24 hour days between two specified dates.

For example, if we want to find full 24hour days between ‘2017-05-27 11:59:00’ and 2017-05-23 12:00:00’ then following would be MySQL query −

mysql> Select TIMESTAMPDIFF(DAY, '2017-05-23 12:00:00' , '2017-05-27 11:59:00');
+---------------------------------------------------------------------------+
| TIMESTAMPDIFF(DAY, '2017-05-23 12:00:00' , '2017-05-27 11:59:00')         |
+---------------------------------------------------------------------------+
| 3                                                                         |
+---------------------------------------------------------------------------+
1 row in set (0.00 sec)

Updated on: 28-Jan-2020

161 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements