Solved

EASY ONE - TSQL - add a year to a date

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Server 2012 r2 and SQL 2014 6 34
Access PS SQLSERVER from powershell 1 30
Using a SUBQUERY for the set variable 10 30
Creating Scalar Function 3 19
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

751 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