Mysql表列是
Starttime - type:datetime, Stoptime - type:datetime
数据
Starttime, stoptime
2013-10-25 09:00:00, 2013-10-25 17:00:00
2013-10-26 09:00:00, 2013-10-26 17:00:00
2013-10-27 09:00:00, 2013-10-27 17:00:00
2013-10-28 09:00:00, 2013-10-28 17:45:00
查询
select, min(starttime), max(stoptime),
SUM(TIME_TO_SEC(TIME_DIFF(stoptime - starttime))) total_hours from mytable
返回秒数,我可以使用TIME_TO_SEC()
将其转换回时间...它以HH:MM:SS
格式给出结果,例如28:45:00
但我需要将 28:45:00 转换为 28.75 小时格式。我该怎么做?
最佳答案
select, min(starttime), max(stoptime),
SUM(TIME_TO_SEC(TIME_DIFF(stoptime - starttime))/3600) total_hours from mytable
关于php - mysql查询中日期时间差的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19051544/