In my older post, I tried to change the date to current date and add 8 hours time.
SQL Server: convert to today then add 8 hours
UPDATE business.dbo.db_schedule
SET nextUpdate= DATEADD(hh, 8,
DATEADD(d, DATEDIFF(D,nextUpdate,Getdate()),
nextUpdate))
where sno=8
note: nextUpdate may be any time in the past.
if I want to go one step further; I want nextdate to be in the future time.
Because if I add 8 hour once, the result may be still a time in the past, I may have to add one more (or even twice) so the result is in the future. Can i do it in one step?
Instead of just adding 8 hours, we multiply 8 by the
CELINGof the number of hours apartnextUpdateis fromGETDATE()e.g. If
nextUpdateis2012-10-01 02:30:00andGETDATE()is currently2012-10-02 15:15:00, then there are 36.75 (rounded up to 37) Hours difference. TheCEILINGof 37 / 8 is 5, which means you will need to add 5 * 8 hours to get a time that is afterGETDATE()yet retains the multiple of 8 hours from your currentnextUpdatevalue.SQLFiddle example of the solution