我想知道如何更改日期

时间:2017-11-24 18:28:00

标签: sql-server sql-server-2014 getdate

例如,数据库中的日期..

2017-11-22 05:00:00
2017-11-22 05:30:00
2017-11-23 05:45:00
2017-11-23 05:50:00
2017-11-24 06:00:00
2017-11-24 06:30:00
2017-11-24 06:05:00

Day 22 is +1 day from current date
Day 23 is +2 days from the current date
The 24th day is +3 days from the current date.

我想结果是:

我想以这种方式改变它。

2017-11-25 05:00:00
2017-11-25 05:30:00
2017-11-26 05:45:00
2017-11-26 05:50:00
2017-11-27 06:00:00
2017-11-27 06:30:00
2017-11-27 06:05:00

我试过了,但失败了。

update Info_Game set IG_StartTime = replace(convert(char(10), IG_StartTime, 20), '2017-11-22', convert(char(10), getdate()+1, 20)) 
update Info_Game set IG_StartTime = replace(convert(char(10), IG_StartTime, 20), '2017-11-23', convert(char(10), getdate()+2, 20)) 
update Info_Game set IG_StartTime = replace(convert(char(10), IG_StartTime, 20), '2017-11-24', convert(char(10), getdate()+3, 20)) 

1 个答案:

答案 0 :(得分:0)

试试这个;

update Info_Game set IG_StartTime = DATEADD(day,1,DATEADD(hour,DATEPART(hour,IG_StartTime),cast(getdate() as date))) where cast(IG_StartTime as date) = '2017-11-22'

update Info_Game set IG_StartTime = DATEADD(day,2,DATEADD(hour,DATEPART(hour,IG_StartTime),cast(getdate() as date))) where cast(IG_StartTime as date) = '2017-11-23'

update Info_Game set IG_StartTime = DATEADD(day,3,DATEADD(hour,DATEPART(hour,IG_StartTime),cast(getdate() as date))) where cast(IG_StartTime as date) = '2017-11-24'