Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-03-14
4
Medium Priority
?
393 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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 …
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

618 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