Solved

EASY ONE - TSQL - add a year to a date

Posted on 2003-11-27
4
2,148 Views
Last Modified: 2011-09-24
I am writing a sproc and simply need to add X years to a smalldatetime (X can vary from 1-10).

Anyone know the syntax?


cheers
n
0
Comment
Question by:niico
  • 2
4 Comments
 
LVL 26

Expert Comment

by:Hilaire
ID: 9833642
select dateadd(y, 1, getdate())

adds 1 year to current date

Hilaire
0
 
LVL 1

Accepted Solution

by:
beavis_shenzhen earned 50 total points
ID: 9835496
not feasible for SQL 2000
"select dateadd(y, 1, getdate())" just add one day to the date ,not one year.

it should be:
select dateadd(year, 1, getdate())
or
select dateadd(yy, 1, getdate())
0
 
LVL 26

Expert Comment

by:Hilaire
ID: 9835583
Yep !
Thks for correcting me beavis_shenzhen
0
 

Author Comment

by:niico
ID: 9837535
Thank you both - beavis gets points as supplied correct answer.

Thx again
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

867 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

18 Experts available now in Live!

Get 1:1 Help Now