Jeff Atwood Jeff Atwood - 1 year ago 79
C# Question

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

Given a

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

Answer Source

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))

However, this assumes you are looking for the western idea of age and not using East Asian reckoning.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download