BethanyW
4Penny.net
Points: 7400

2/23/2024 9:31:26 AM

SQL Server - get a person's age from the current date and birth date

* This article, and all our great SQL (General) documentation, Is available on the SQL (General) menu

This is a little more complicate than you might think. Simply using DATEDIFF won't work correctly, because it only subtracts the 'year' portion of the date. It doesn't take into account if the month/day is before or after the current date. 

I've come across a formula that works, and it's not too complicated. See below. 

4Penny.net
Version: Unknown or N/A
Section: SQL Scripts,SQL for Beginners
Table Definition Quick Links
All Tables
SOP Tables
RM Tables
GL Tables
POP Tables
HR Tables
PM Tables
UPR Tables
IV Tables
Olympic Tables
3