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.
| Author |
Topic |
|
DeepakNewton
Starting Member
39 Posts |
Posted - 2009-09-24 : 14:12:39
|
| Hi All,I am new to Sql server , I Need to get the date from the column + current year + one calender year.... (8/20/2009 means it should return 8/19/2010 also consider leap year)I have used dateadd(yy,datediff(yy, cr_date ,getdate())+1, cr_date) But its returning 8/20/2010 , but I need 8/19/2010Any suggestion/solution would be highly Appreciated ....Thanks and Regards,Deepak N |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-09-24 : 14:21:03
|
So you have to add 1 year and subtract 1 day.select dateadd(dd,-1,dateadd(yy,1,getdate())) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
DeepakNewton
Starting Member
39 Posts |
Posted - 2009-09-24 : 14:58:55
|
| Hi fredThanks a Lot , I Modified Select dateadd(dd,-1,dateadd(yy,datediff(yy, cr_date,getdate())+1,cr_date)) from tblPol_TrgIts working , Will it consider and work for the LEAP year also? |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-09-24 : 17:21:23
|
select dateadd(dd,-1,dateadd(yy,1,'20000229')) -- 2000 was a leap year.gives - correct - the 2001-02-27 No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|
|
|