?
Solved

script in sql - to add 2 years to a DATETIME column?

Posted on 2011-03-14
4
Medium Priority
?
389 Views
Last Modified: 2012-06-22
how do you script in sql - to add 2 years to a DATETIME column?


UPDATE db_table
SET [AdjustedDateTime] = [CurrentDateTime] + 2 years !
0
Comment
Question by:amillyard
[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
4 Comments
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 2000 total points
ID: 35134218


UPDATE db_table
SET [AdjustedDateTime] = DATEADD(YY, 2, [CurrentDateTime])
0
 

Author Closing Comment

by:amillyard
ID: 35134226
thank you :-)
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35134227

or if you want to add 2 years to todays date

UPDATE db_table
SET [AdjustedDateTime] = DATEADD(YY, 2, GETDATE())
0
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 35134264
DECLARE  @StoreOpeningDate  DATETIME
DECLARE  @tmpDate  DATETIME

SET @StoreOpeningDate = '2006-08-01'

--Adding 2 Years
SET @tmpDate = dateadd(yy, 2, @StoreOpeningDate)

select @tmpDate
 
END

Source: http://www.experts-exchange.com/Programming/Languages/SQL_Syntax/Q_24829281.html?sfQueryTermInfo=1+10+30+add+datetim+year
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

762 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