Maged Samaan
Maged Samaan

Reputation: 1752

Update date time column

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

Upvotes: 3

Views: 2242

Answers (3)

Andy Singh
Andy Singh

Reputation: 29

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') 

Upvotes: 1

Curtis
Curtis

Reputation: 103338

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

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

Upvotes: 1

marc_s
marc_s

Reputation: 754230

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

Upvotes: 8

Related Questions