Solved

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

Posted on 2011-03-14
4
376 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
  • 2
4 Comments
 
LVL 32

Accepted Solution

by:
ewangoya 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:ewangoya
ID: 35134227

or if you want to add 2 years to todays date

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

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 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