mslowiak
mslowiak

Reputation: 1838

Adding TIME to TIME

I want to add two TIME variables.

DECLARE @time1 TIME
DECLARE @time2 TIME
DECLARE @outt TIME
SET @time1 = '00:00:01'
SET @time2 = '03:00:21'
SET @outt = @time1 + @time2

When I try to do this I got error like:

'Operand data type time is invalid for add operator.'

Upvotes: 0

Views: 55

Answers (1)

S3S
S3S

Reputation: 25112

You will want to use DATEADD. Here is how you add the one second.

DATEADD(ss,@time2,1)

MSDN Reference

Or....

DECLARE @time1 TIME
DECLARE @time2 TIME
DECLARE @outt TIME
SET @time1 = '00:00:04'
SET @time2 = '03:00:21'

declare @s int = (select (datepart(hh,@time1) * 60 * 60) + (datepart(mi,@time1) * 60) + datepart(ss,@time1))
select @s

select dateadd(ss,@s,@time2)

Upvotes: 3

Related Questions