How can I use DATEDIFF to return the difference between two dates in years, months and days in SQL Server 2005
DATEDIFF (date , dat
TL;DR approximates years & months without having to create a function.
I found this question searching for "get years months from datediff". I was looking for something a bit quicker (and yeah, probably dirtier) than the above function-creating solutions.
I came up with the following in-line sql which approximates the years and months. Sufficient for my own purposes, which is getting a count of events grouped by user's rough age at the time.
select cast(datediff(event_datetime, dateofbirth)/365.25 as unsigned) as years,
cast((mod(datediff(event_datetime, dateofbirth),365.25))/30.4375 as unsigned) as months
from tablename
;