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 |
cognos79
Posting Yak Master
241 Posts |
Posted - 2007-09-27 : 14:42:06
|
How do i find out if two dates are exactly 3 yrs apart or not.stdate: 12/1/2005enddate: 11/10/2008. the result shld 2 yrs .I dont care abt the days. just the months and years. |
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-09-27 : 14:50:48
|
Use Datediff.Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
Kristen
Test
22859 Posts |
Posted - 2007-09-27 : 15:08:01
|
"exactly 3 yrs apart or not"<sigh!>What does that mean?Same day same month 3 years ago?What is the correct value for 29-Feb?Kristen |
 |
|
Kristen
Test
22859 Posts |
Posted - 2007-09-27 : 15:10:52
|
I suppose you could doSELECT DATEDIFF(Month, '20051201', '20081110') = 36That satisfies the "months and years" requirement, but I don't see how that is "exactly 3 yrs apart"Note that using DATEDIFF on a column will prevent the query using any index on that column, so performance may be sub-optimal.Kristen |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-09-28 : 03:07:56
|
http://www.sqlteam.com/article/datediff-function-demystified E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|