Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Always add 1 year to datetime? How-to 1

Status
Not open for further replies.

sqlcasey

Programmer
Sep 21, 2006
150
US
Hi,

I have a situation where I need to write a query that will always and consistently add ONE YEAR to a datetime field.

For example, if renewal date is 2006-10-23, then I need to be able to add one year to that date so that it is exactly 2007-10-23. However, I realize that just adding 365 to the field won't always result in accurate addition. Case in point: adding 365 to 2008-01-01 will get you 2008-12-31. Not what I want.

Is there a way to code this correctly?? I'm sure it involves the use of some date function, but I can't think of it at the moment...

Thanks
 
Hello,

You can use the function DATEADD:

DATEADD ( datepart , number, date )

So If you want to add 1 year to your original date:

DATEADD (yy, 1, <Your Date Field>)

You can look it up in BOL for more detailed explanation

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top