2012-12-20 75 views
0

我想知道兩個日期之間的時間差異。 例如:DIFFTIME的選擇問題

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): 

爲什麼不起作用?

回答

2

嘗試:

SELECT HOUR(TIMEDIFF('2012-12-19 22:00:00','2012-12-10 19:00:00')); 
+0

感謝。有用。 –

0

這可以解決您的問題:

SELECT TIME_FORMAT(TIMEDIFF('2012-12-19 22:00:00','2012-12-10 19:00:00'),'%H');