| Author |
Topic |
|
shemayb
Posting Yak Master
159 Posts |
Posted - 2007-12-19 : 18:45:35
|
| hi! i have this following query:Select DATEADD(YEAR, -2, @sDate),(dateadd(dd,-(day(dateadd(yy,1,@sDate))),dateadd(yy,1,@sDate)))..the results of these are:2005-01-01 ,2007-12-31 but i want 2007-12-31 to be 2005-12-31..how can i do that using dateadd function?Funnyfrog |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-12-19 : 18:49:25
|
| Subtract off 2 years using DATEADD.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
shemayb
Posting Yak Master
159 Posts |
Posted - 2007-12-19 : 18:51:35
|
| i will subract this one (dateadd(dd,-(day(dateadd(yy,1,@sDate))),dateadd(yy,1,@sDate))) by 2?Funnyfrog |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-12-19 : 18:52:37
|
[code]SELECT DATEADD(YEAR, DATEDIFF(YEAR, '19021231', CURRENT_TIMESTAMP), '19000101'), DATEADD(YEAR, DATEDIFF(YEAR, '19021231', CURRENT_TIMESTAMP), '19001231')[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-12-20 : 01:47:47
|
quote: Originally posted by shemayb hi! i have this following query:Select DATEADD(YEAR, -2, @sDate),(dateadd(dd,-(day(dateadd(yy,1,@sDate))),dateadd(yy,1,@sDate)))..the results of these are:2005-01-01 ,2007-12-31 but i want 2007-12-31 to be 2005-12-31..how can i do that using dateadd function?Funnyfrog
Instead of (dateadd(dd,-(day(dateadd(yy,1,@sDate))),dateadd(yy,1,@sDate))) useDATEADD(DAY,-1,DATEADD(YEAR,1,DATEADD(YEAR, -2, @sDate)))MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|