Question

nextUpdate can be any date time value in the past. I'm trying to update the nextUpdate field to today's date but keeping the time unchanged and then add 8 hours.

I get

error converting string to datetime

T-SQLe:

UPDATE 
    business.dbo.db_schedule  
SET 
    nextUpdate = DATEADD(hh, 8, CONVERT(datetime, CONVERT(VARCHAR(8), GETDATE(), 111) + ' ' + CONVERT(VARCHAR(8), nextUpdate, 108), 111))  
WHERE
    sno = 8

datetime format in my location is 111

Was it helpful?

Solution

UPDATE business.dbo.db_schedule
SET nextUpdate= DATEADD(hh, 8,
                DATEADD(d, DATEDIFF(D,nextUpdate,Getdate()),
                          nextUpdate))
where sno=8
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top