SQL Server: convert to today then add 8 hours

2019-07-23 17:36发布

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

1条回答
闹够了就滚
2楼-- · 2019-07-23 18:15
UPDATE business.dbo.db_schedule
SET nextUpdate= DATEADD(hh, 8,
                DATEADD(d, DATEDIFF(D,nextUpdate,Getdate()),
                          nextUpdate))
where sno=8
查看更多
登录 后发表回答