gpt4 book ai didi

sql - 如何计算MySQL中日期时间之间的间隔?

转载 作者:IT王子 更新时间:2023-10-29 00:31:42 25 4
gpt4 key购买 nike

例如,如何计算这两个日期时间之间的间隔:

2009-09-18 00:00:00

2009-10-17 00:00:00

编辑

我的意思是获取格式为年-月-日时:分:秒的区间

最佳答案

使用 datediff 怎么样? :

mysql> select abs(datediff('2009-09-18 00:00:00', '2009-10-17 00:00:00'));
+-------------------------------------------------------------+
| abs(datediff('2009-09-18 00:00:00', '2009-10-17 00:00:00')) |
+-------------------------------------------------------------+
| 29 |
+-------------------------------------------------------------+
1 row in set (0.00 sec)

引用手册:

DATEDIFF() returns expr1 – expr2 expressed as a value in days from one date to the other. expr1 and expr2 are date or date-and-time expressions.
Only the date parts of the values are used in the calculation.

关于sql - 如何计算MySQL中日期时间之间的间隔?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1458345/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com