Solved

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

Posted on 2011-03-14
4
383 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 500 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

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