Advertise with us

How do I calculate someone's age

Hi Expert!

Given a DateTime representing a person's birthday, how do I calculate their age?

Thanks in advance. 
Last updated:5/29/2013 9:04:56 AM

1 Answers

AVADHESH PATEL
AVADHESH PATEL

Hi Jeet!


For some reason Jeff's code didn't seem simple enough. To me this seems simpler and easier to understand:

DateTime today = DateTime.Today;
int age = today.Year - bday.Year;
if (bday > today.AddYears(-age)) age--;

Answer