SQL modify date by two days using update query

Is it possible to use an update query to change a time value on every row by 2 days, say using the dateadd function?
pansophyAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
chapmandewConnect With a Mentor Commented:
update t
set datefield = dateadd(d, 2, datefield)
from tablename t
0
 
jamesguCommented:
another easy ways is:

update table_name
set column_name = column_name - 2 /* or + 2 */

0
 
chapmandewCommented:
assuming that your system is setup to subtract days rather than hours or months, etc.
0
 
pansophyAuthor Commented:
thanks!
0
 
jamesguCommented:
http://msdn.microsoft.com/en-us/library/aa276859(SQL.80).aspx



B. Use the addition operator to add days to date and time values
 
This example adds a number of days to a datetime date.
 
USE master
GO
SET NOCOUNT ON
DECLARE @startdate datetime, @adddays int
SET @startdate = '1/10/1900 12:00 AM'
SET @adddays = 5
SET NOCOUNT OFF
SELECT @startdate + 1.25 AS 'Start Date', 
   @startdate + @adddays AS 'Add Date'
 
Here is the result set:
 
Start Date                  Add Date                    
--------------------------- --------------------------- 
Jan 11 1900  6:00AM         Jan 15 1900 12:00AM         
 
(1 row(s) affected)

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.