Home  >  Article  >  Database  >  How to calculate the number of complete 24-hour days between two specified dates in MySQL?

How to calculate the number of complete 24-hour days between two specified dates in MySQL?

WBOY
WBOYforward
2023-09-09 18:53:07725browse

如何计算 MySQL 中两个指定日期之间的完整 24 小时天数?

In the DATEDIFF() function, only the date part of the value is used for calculation, so we can use the TIMESTAMPDIFF() function to calculate the number of complete 24-hour days between two specified dates.

For example, if we want to find the complete 24-hour days between '2017-05-27 11:59:00' and 2017-05-23 12:00:00', then the following is the 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)

The above is the detailed content of How to calculate the number of complete 24-hour days between two specified dates in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete