Reputation: 21928
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
Upvotes: 1
Views: 15924
Reputation: 26120
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.
Upvotes: 14
Reputation: 24105
Use dateadd
:
update TableLastCalls
set NEXT_UPDATE_TIME = dateadd(hh, 1, NEXT_UPDATE_TIME)
Upvotes: 2
Reputation: 755321
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.
Upvotes: 5
Reputation: 147344
UPDATE TableLastCalls
SET [NEXT_UPDATE_TIME] = DATEADD(hh, 1, [NEXT_UPDATE_TIME])
WHERE...
Upvotes: 3