Skip to content
Advertisement

How to calculate age (in years) based on Date of Birth and getDate()

I have a table listing people along with their date of birth (currently a nvarchar(25))

How can I convert that to a date, and then calculate their age in years?

My data looks as follows

I would like to see:

Advertisement

Answer

There are issues with leap year/days and the following method, see the update below:

try this:

OUTPUT:

UPDATE here are some more accurate methods:

BEST METHOD FOR YEARS IN INT

you can change the above 10000 to 10000.0 and get decimals, but it will not be as accurate as the method below.

BEST METHOD FOR YEARS IN DECIMAL

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement