我有两次char start_time
和end_time
。如何找到它们之间的区别?
例如我的start_time
是上午10:00而end_time
是上午11:15,那么时差应显示为1:15
答案 0 :(得分:1)
试试这个:
declare @starttime varchar(10)='10:00 AM'
declare @endtime varchar(10)='11:15 AM'
select cast((datediff(Mi,convert (time,@starttime),
convert (time,@endtime))/60) as varchar(5))+':'+
cast((datediff(Mi,convert (time,@starttime),
convert (time,@endtime))%60) as varchar(5))
1:15
答案 1 :(得分:0)
答案 2 :(得分:0)
试试这个:
SELECT left(CONVERT(varchar(12), DATEADD(ms, DATEDIFF
(ms, CAST('10:00 AM' AS DATETIME), CAST('11:15 AM' AS DATETIME)) , 0), 108),5);
<强>结果强>
1时15
SELECT left(CONVERT(varchar(12), DATEADD(ms, DATEDIFF
(ms, CAST('09:00 AM' AS DATETIME), CAST('11:15 AM' AS DATETIME)) , 0), 108),5);
<强>结果强>
02:15
答案 3 :(得分:0)
你可以这样做:
SELECT LEFT(convert(varchar,CAST('11:15 AM AS DATETIME)-CAST('10:00 AM' AS DATETIME),108),5)
答案 4 :(得分:0)
尝试此查询,它在MySQL中运行良好:
select TIME_FORMAT((TIME( STR_TO_DATE( '11:15 PM', '%h:%i %p' ) ) - TIME( STR_TO_DATE( '10:00 PM', '%h:%i %p' ))),'%h:%i');