View Single Post
 
Old November 12th, 2005, 06:08 AM
jawg62 jawg62 is offline
Registered User
 
Join Date: Nov 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

-- Be careful with DateDiff yy - that just returns the years between two dates and *not* elapsed time. Consider:

SELECT DateDiff(yy,'12/31/2000','1/1/2005') AS YearDiff, FLOOR(DateDiff(dd,'12/31/2000','1/1/2005')/365.25) As CloserToCorrect

/*
YearDiff returns 5, 2005-2000. This answer is incorrect, our example person just had their 4th birthday the day before.
The CloserToCorrect field gets us a lot closer to an accurate age of 4.
Date / Age
12/31/2000 / 0
12/31/2001 / 1
12/31/2002 / 2
12/31/2003 / 3
12/31/2004 / 4
12/31/2005 / 5
*/