Solved

SQL modify date by two days using update query

Posted on 2008-09-30
5
645 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

729 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