I'm calculating employee time and saving on sql server,
calculate time like this 1:00:00 + 1:00:00 = 2:00:00 in sql server.
Example :
When first time i insert the working hrs as 3:00:00,
and second time if i give the working hrs as 4:00:00
i need to update the value as 7:00:00.
The datatype of this column is time datatype.
Thanks In Advance :)))))
Jignesh TrivediPosted May 8, 2014, 2:46 AM
hi,
I think it is not possible add two time directly in SQL server
fir you have to convert second time in to total second and using Dateadd function add all second to fist time
like
declare @time time = '03:12:00'
declare @time1 time = '00:55:00'
declare @timestring varchar(10) = cast(@time1 as varchar(10))
declare @int int
select @int = (substring(@timestring,1,2) * 360) +
(substring(@timestring,4,2) * 60) +
substring(@timestring,7,2)
Print @int
set @time = DATEADD(s,@int,@time)
print @time
hope this will help you.
Nitesh KejriwalPosted May 8, 2014, 2:07 AM
INSERT INTO TABLE_NAME(TIME_COLUMN) VALUES('3:00:00')
Get the ID of the employee record for whom time needs to be updated -
DECLARE @Time time
UPDATE TABLE_NAME SET TIME_COLUMN = TIME_COLUMN+ @Time WHERE ID=@RecordID