0

我想知道两个日期之间的时差。例如:

    SELECT TIMEDIFF('2012-12-19 22:00:00','2012-12-10 19:00:00');
+-------------------------------------------------------+
| TIMEDIFF('2012-12-19 22:00:00','2012-12-10 19:00:00') |
+-------------------------------------------------------+
| 219:00:00                                             |
+-------------------------------------------------------+
1 row in set (0.00 sec)

现在我想提取时间。

mysql> SELECT HOUR(SELECT TIMEDIFF('2012-12-19 22:00:00','2012-12-10 19:00:00'));
ERROR 1064 (42000): 

为什么不起作用?

4

2 回答 2

2

尝试:

SELECT HOUR(TIMEDIFF('2012-12-19 22:00:00','2012-12-10 19:00:00'));
于 2012-12-20T03:54:00.970 回答
0

这可以解决您的问题:

SELECT TIME_FORMAT(TIMEDIFF('2012-12-19 22:00:00','2012-12-10 19:00:00'),'%H');
于 2016-01-20T08:47:09.353 回答