Home > Database > Mysql Tutorial > 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
Release: 2023-09-09 18:53:07
forward
758 people have browsed it

如何计算 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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template