例如,如何计算这两个日期时间之间的间隔:
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()
returnsexpr1 – 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/