• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 654
  • Last Modified:

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?
0
pansophy
Asked:
pansophy
  • 2
  • 2
1 Solution
 
chapmandewCommented:
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now