Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
for example, existing time is 20hours and that record will be update to 28hours by adding 8 hours
in an update stored procedure.

What I have tried:

TotalTime = CONVERT(TIME, CONVERT(NVARCHAR, (DATEADD(SECOND, DATEDIFF(SECOND, 0, @TotalTime), @OldTotalTime))))
Posted
Updated 11-May-21 10:46am
v2
Comments
Richard MacCutchan 6-May-21 6:57am    
What is wrong with just adding 8 to the total hours?
Mani kanta 2021 6-May-21 7:11am    
It shows 24hr format and then the result is 4hours

What the heck is that supposed to do? Why are you converting to seconds, adding the old seconds, converting that to a string (hoping that the server settings don't change), and then converting the string to a TIME value?

The simplest solution is: don't use TIME at all. Instead, use an integer which represents the smallest interval you are interested in: if your cumulative time is whole hours, then an integer value of 1 is an hour. If your cumulative time is in "15 minute blocks", then a value of 1 is one minute. And so on.
Then it's trivial:
SQL
@TotalTime = @TotalTime + 8 * 60
to add eight hours to a minute based count.

To convert back to your units is trivial: divide and modulus make it so!
 
Share this answer
 
v2
Try this:
SQL
<pre>SELECT FORMAT(totaltime,'hh') + 8


This works in SQL server 2012 and above
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900