SQL Server:转换为今天,然后添加8小时 [英] SQL Server: convert to today then add 8 hours
本文介绍了SQL Server:转换为今天,然后添加8小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
nextUpdate
可以是过去的任何日期时间值.我试图将nextUpdate
字段更新为今天的日期,但保持时间不变,然后增加8小时.
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.
我知道
将字符串转换为日期时间时出错
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
格式为111
datetime
format in my location is 111
推荐答案
UPDATE business.dbo.db_schedule
SET nextUpdate= DATEADD(hh, 8,
DATEADD(d, DATEDIFF(D,nextUpdate,Getdate()),
nextUpdate))
where sno=8
这篇关于SQL Server:转换为今天,然后添加8小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文