Solved

SQL modify date by two days using update query

Posted on 2008-09-30
5
643 Views
Last Modified: 2012-05-05
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
Comment
Question by:pansophy
  • 2
  • 2
5 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 22608192
update t
set datefield = dateadd(d, 2, datefield)
from tablename t
0
 
LVL 9

Expert Comment

by:jamesgu
ID: 22608438
another easy ways is:

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

0
 
LVL 60

Expert Comment

by:chapmandew
ID: 22608455
assuming that your system is setup to subtract days rather than hours or months, etc.
0
 

Author Closing Comment

by:pansophy
ID: 31501667
thanks!
0
 
LVL 9

Expert Comment

by:jamesgu
ID: 22608595
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
push and Pull replication 31 48
access to sql migration 5 24
SQL Server In place upgrade from 2012 to 2014 12 22
A question about syntax 5 27
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question