Guides › Age from a date
How to work out age in SQL Server (and why DATEDIFF(year) lies)
DATEDIFF(year, dob, today) counts New Year’s Eves, not birthdays. Someone born 31 December 2000 is “26” on 1 January 2026. They are 25.
The honest age
SELECT customer_id, first_name, date_of_birth,
DATEDIFF(year, date_of_birth, GETDATE())
- CASE WHEN DATEADD(year, DATEDIFF(year, date_of_birth, GETDATE()), date_of_birth) > CAST(GETDATE() AS date)
THEN 1 ELSE 0 END AS age
FROM Customers;
Work out the year gap, then subtract one if this year’s birthday is still in the future.
DATEDIFF(year) on its own
Fine for a rough “how many year boundaries.” Wrong on a form, a discount, or anything legal-looking. Same boundary trick as DATEDIFF.
Age in days or months
SELECT DATEDIFF(day, date_of_birth, CAST(GETDATE() AS date)) AS age_days;
Days are honest. Months have the same boundary issue as years.
Try it on Harbour & Co
James Rowe (Sales Manager) needs this now: “Need last week’s orders over £50 for the 10am. Don’t include today. Newest first.” Write the query, run it, send the results. Free.
Take the ticket →Learn it on a real ticket
Monday is free on WorkSQL. A colleague’s ticket lands, you write the T-SQL, we mark it. No videos. Five minutes.
Clock in free See Monday’s tickets