使用mysql
2个日期:start_date
和end_date
。
改变后
TIMEDIFF(start_date, end_date) AS time_diff
我想SUM()所有time_diff所以我试试这个
SUM(TIMEDIFF(start_date, end_date)) AS time_diff
这回归了我不期望的东西 我做错了什么?
修改
SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(end_date, START_DATE)))) AS time_diff
完美无缺
答案 0 :(得分:0)
end_date
应该是第一个而start_date
秒,否则你会得到负值作为输出:
SUM(TIME_DIFF(CAST(end_date AS DATETIME), CAST(start_date AS DATETIME))) AS time_diff
答案 1 :(得分:0)
SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(end_date, START_DATE)))) AS time_diff