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
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
UPDATE TableLastCalls
SET [NEXT_UPDATE_TIME] = DATEADD(hh, 1, [NEXT_UPDATE_TIME])
WHERE...
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.
Use dateadd
:
update TableLastCalls
set NEXT_UPDATE_TIME = dateadd(hh, 1, NEXT_UPDATE_TIME)