ProAnswers.org

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

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

1 Like

this seems simpler and easier to understand:
try this…

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

int now = int.Parse(DateTime.Today.ToString(“yyyyMMdd”));
int dob = int.Parse(dateDOB.ToString(“yyyyMMdd”));
string dif = (now - dob).ToString();
string age = dif.Substring(0, dif.Length - 4);