如何使用格式(HH:mm:ss)在MySQL查询中减去时间

时间:2014-06-17 09:21:50

标签: mysql sql datetime select timestamp

timestart = 16:46:33

timeend = 16:48:22

预期结果= 00:01:49

我的查询:

Select timestart , timeend, (timeend - timestart) as rangetime from time; 

4 个答案:

答案 0 :(得分:0)

检查MySQL TIMEDIFF功能。

试试这个:

SELECT timestart, timeend, TIMEDIFF(timeend, timestart) AS rangetime 
FROM time;

答案 1 :(得分:0)

尝试使用SubTime

Select timestart , timeend, SUBTIME(timestart ,timeend) As rangetime from time; 

<强> FIDDLE DEMO

答案 2 :(得分:0)

select Timestart,Timeend,subtime(Timestart,Timeend) as rangetime from time;

More Info

答案 3 :(得分:0)

检查 TIMEDIFF 功能

试试这个

    SELECT timestart,
       timeend,
       TIMEDIFF(timeend,timestart) AS rangetime
FROM `time`;