How do I calculate someone's age in C#?

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

This question and answers originated from www.stackoverflow.com
Question by (7/31/2008 11:40:59 PM)

Answer

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

DateTime now = DateTime.Today;
int age = now.Year - bday.Year;
if (bday > now.AddYears(-age)) age--;
Answer by

Find More Answers
Related Topics  c#  datetime
Related Questions