Solved

EASY ONE - TSQL - add a year to a date

Posted on 2003-11-27
4
2,150 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
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.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

808 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