views:

137

answers:

5

How can we update datetime value in a column using sql

say, if we want to update any of datetime values by adding an hour or 5 minutes etc.

UPDATE TableLastCalls
SET [NEXT_UPDATE_TIME] =  ?? // want to add an hour
+4  A: 

Use the DATEADD function.

UPDATE TableLastCalls
SET [NEXT_UPDATE_TIME] =  DATEADD(hour, 1, [NEXT_UPDATE_TIME])
womp
+3  A: 
UPDATE TableLastCalls
SET [NEXT_UPDATE_TIME] = DATEADD(hh, 1, [NEXT_UPDATE_TIME])
WHERE...
AdaTheDev
+4  A: 
UPDATE TableLastCalls
SET [NEXT_UPDATE_TIME] = DATEADD(MINUTE, 5, NEXT_UPDATE_TIME)

UPDATE TableLastCalls
SET [NEXT_UPDATE_TIME] = DATEADD(HOUR, 2, NEXT_UPDATE_TIME)

and so on - lots of options with DATEADD to add specific amounts of time to your date.

See the MSDN docs on DATEADD for all the details.

marc_s
+2  A: 

Use dateadd:

update TableLastCalls
set NEXT_UPDATE_TIME = dateadd(hh, 1, NEXT_UPDATE_TIME)
Roatin Marth
+6  A: 

You can use the DATEADD function:

UPDATE TableLastCalls
SET [NEXT_UPDATE_TIME] = DATEADD(hour, 1, [NEXT_UPDATE_TIME])

This will add 1 hour. Use DATEADD(minute, 5, [NEXT_UPDATE_TIME]) instead to add 5 minutes.

Phil Ross