我想添加两个时间戳,例如' 03:59:39' 03:43:04'在SQL Server中我需要两个时间戳之和的结果是7小时42分43秒。
没有任何演员......任何人都可以建议吗?
答案 0 :(得分:3)
TRY this
DECLARE @TIME1 TIME(0)
,@TIME2 TIME(0);
SELECT @TIME1 = CONVERT(TIME(0), '2013-07-20 03:59:39')
,@TIME2 = CONVERT(TIME(0), '2013-07-25 03:43:04');
SELECT @TIME1 AS [@REQUESTEDTIME]
,@TIME2 AS [@TIMEINTERVEL];
SELECT DATEADD(SECOND, DATEDIFF(SECOND, '00:00:00', @TIME1), @TIME2) AS FINALRESULT;
Try this one also
DECLARE @TimeVal TIME
,@TotalTime TIME;
SET @TimeVal = '03:59:39';
SET @TotalTime = '03:43:04'
SELECT @TimeVal
,@TotalTime
,dateadd(hour, DATEPART(HOUR, @TotalTime), dateadd(minute, DATEPART(MINUTE, @TotalTime), dateadd(ss, DATEPART(SECOND, @TotalTime), @TimeVal)))