Solved

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

Posted on 2011-03-14
4
375 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
Comment Utility


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

Author Closing Comment

by:amillyard
Comment Utility
thank you :-)
0
 
LVL 32

Expert Comment

by:ewangoya
Comment Utility

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
Comment Utility
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

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 …
After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now