问题
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:
UPDATE business.dbo.db_schedule
SET nextUpdate= DATEADD(hh, 8,
DATEADD(d, DATEDIFF(D,nextUpdate,Getdate()),
nextUpdate))
where sno=8
来源:https://stackoverflow.com/questions/12674274/sql-server-convert-to-today-then-add-8-hours