Using the DATEDIFF function using years as the interval often doesn't yield accurate results. For example, a person with a birthday a week from today:SELECT DATEDIFF(yyyy, '6/18/1980', GETDATE())
This person is still 23, however SQL rounds it up by default. Averaging ages using this would deffinitely yield innacurate results.Here is the code that I am currently using to accomplish said task:SELECT AVG(CAST(DATEDIFF(dd, DOB, GETDATE()) AS float) / 365.25) AS AverageAge FROM Customers
The .25 is because every fourth year is a leap year.Has anyone come across a similar situation? If so, what code did you use to gather this information? I know that it could be done using more code, however I'm trying to keep this as simple and quick as possible, as the web based report this is part of is already chock full of fairly resource intensive queries.Jay