Solved

EASY ONE - TSQL - add a year to a date

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Microsoft SQL query 7 39
SQL Backup skipping a few tables 7 25
sql query 7 35
sql calculate averages 18 24
I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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…

708 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

19 Experts available now in Live!

Get 1:1 Help Now