如何使用格式(HH:mm:ss)在MySQL查询中进行Substract Time

时间:2022-03-03 16:31:47

timestart = 16:46:33

timestart = 16:46:33

timeend = 16:48:22

timeend = 16:48:22

Expected Result = 00:01:49

预期结果= 00:01:49

My Query:

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

4 个解决方案

#1


0  

Try with SubTime

尝试使用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  

Check TIMEDIFF function

检查TIMEDIFF功能

Try this

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

#4


0  

Check MySQL TIMEDIFF function.

检查MySQL TIMEDIFF函数。

Try this:

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

#1


0  

Try with SubTime

尝试使用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  

Check TIMEDIFF function

检查TIMEDIFF功能

Try this

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

#4


0  

Check MySQL TIMEDIFF function.

检查MySQL TIMEDIFF函数。

Try this:

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