Lists the difference between dates in years, months, days
Q&A for professional and enthusiast programmers
-- How Old are You -- Lists the difference between dates in years, months, days WITH dates AS ( SELECT '1996-03-15' AS startdate, GETDATE() AS enddate) SELECT DATEDIFF(yy, t.startdate, t.enddate) AS years, DATEDIFF(mm, DATEADD(yy, DATEDIFF(yy, t.startdate, t.enddate), t.startdate), t.enddate) AS months, DATEDIFF(dd, DATEADD(mm, DATEDIFF(mm, DATEADD(yy, DATEDIFF(yy, t.startdate, t.enddate), t.startdate), t.enddate), DATEADD(yy, DATEDIFF(yy, t.startdate, t.enddate), t.startdate)), t.enddate) AS days FROM dates t