Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Dateadd

Author  Topic 

satheesh
Posting Yak Master

152 Posts

Posted - 2012-01-19 : 10:23:14
Dear All,

I would like to add 365 days/1 year to startdate to find end date
i try to use -> DateAdd(day, 365, startdate).Returns

Startdate Enddate
2011-03-19 - 2012-03-18
2011-02-03 - 2012-02-03

DATEADD(yy, 1, startdate) also returns
2011-02-03 - 2012-02-03

Second one need to be '2012-02-02'.How to modify the above date add function.I need to update all records from 2007 to till date.
Any help will be highly appreciated.

Thanks

Reagrds,
SG

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-19 : 10:28:12
DATEADD(year, 1, startdate)

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

satheesh
Posting Yak Master

152 Posts

Posted - 2012-01-19 : 10:34:39
Thanks for your reply x002548

I am getting the same error [DATEADD(year, 1, startdate)]

Startdate Endate
2011-03-19 2012-03-19

Enddate need to be '2012-03-18'

Thanks

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-01-19 : 10:40:54
I don't believe that the result needs to be '2012-02-02' but I belive you meaned 2012-02-03 + 365 should give 2013-02-02 because of the leap year and this happens correct.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -