我有两列INTIME,OUTTIME为09:03:01为INTIME,18:06:00 AS OUTTIME这些列的数据类型现在为varchar类型我想计算OUTTIME减去INTIME之间的持续时间然后我需要获取持续时间如9:02:59
答案 0 :(得分:1)
只需减去它们:
DECLARE @INTIME DATETIME, @OUTTIME DATETIME
SELECT @INTIME = CONVERT(DATETIME,'09:03:01'), @OUTTIME = CONVERT(DATETIME,'18:06:00')
SELECT CONVERT(VARCHAR(10),@OUTTIME - @INTIME,108)
输出:09:02:59
答案 1 :(得分:0)
试试这个。这可以帮到你。
select CONVERT(CHAR(8),DATEADD(second,datediff(second, cast('09:03:01' as datetime),cast('18:06:00' as datetime)),0),108) as duration
在线查看