2012-10-23 100 views
0

如何在日历小时内获取两个日期时间之间的差异(以调整夏令时)。如何在日历小时内获取日期时间差异

这是SO贴子上建议的:time_to_sec(timediff(to_date, from_date))

但是我得到了奇怪的警告:

select time_to_sec("65:00:00"); 
show warnings; -- nonthing 

select time_to_sec("984:00:00"); 
show warnings; -- Truncated incorrect time value: '984:00:00 

难道我只是忽略这些警告?或者,还有更好的方法?

回答

2

由于stated in the docs,time_to_diff返回一个TIME值并且被限制在TIME字段类型支持的范围内:-838:59:59 - > 838:59:59。您的984小时超出最大支持值150个小时。

+0

那么,有没有另一种方法来获得两个日期时间之间的差异几小时? – Bradford

+0

使用unix时间戳和一些视角,例如'(unix_timestamp(time1) - unix_timestamp(time2))/(60 * 60)'。 unix时间戳只是整数,表示从1/70开始的秒数。 –