开发者

Update date time column

开发者 https://www.devze.com 2023-03-17 14:19 出处:网络
I want to update a DateTime filed with value like 2008-04-22 00:00:00.000 and add a fixed time to it + 1 Hour

I want to update a DateTime filed with value like 2008-04-22 00:00:00.000 and add a fixed time to it + 1 Hour

example i have the column like 2008-04-22 00:00:00.000 to be like 2008-04-22 01:00:00.000

开发者_运维问答

thanks


Easy:

UPDATE dbo.YourTable
SET YourColumn = DATEADD(H, 1, YourColumn)
WHERE (some condition here)

DATEADD is a handy method to add or subtract any kind of amount of seconds, minutes, days even from a DATETIME value


UPDATE TableName SET ColumnName=DATEADD(hh, 1, ColumnName)

Where TableName is your table, and ColumnName is a datetime column


Update DateTime column with 00:00:00 Time - Keep Date unchanged, only time changes

update [EmployeeSchedule] 
set [SchedDate] = CONVERT(DATETIME, CONVERT(VARCHAR(50), [SchedDate], 102) + ' 00:00:00') 
0

精彩评论

暂无评论...
验证码 换一张
取 消