我需要在MySQL中找到以下日期的小时差 - 我可以使用Datediff函数吗?
2014-01-01 07:27:21 and 2014-02-01 11:29:00
我尝试使用DATEDIFF(MINUTE,'2014-01-01 07:27:21','2014-01-01 11:29:00')
,但显然MySQL发出错误。
答案 0 :(得分:2)
分钟的时差:
SELECT ROUND(TIME_TO_SEC(timediff(date1,date2))/60) AS diff
示例:
SELECT ROUND(TIME_TO_SEC(timediff('2014-01-01 11:29:00','2014-01-01 07:27:21'))/60) AS diff
结果:
242
小时的时差:
SELECT ROUND(TIME_TO_SEC(timediff(date1,date2))/60/60) AS diff
如果您需要使用分数的小时数,请删除ROUND。