Home > DeveloperSection > Forums > How do I calculate someone's age in C#?
Chintoo Semi

Total Post:135

Posted on    December-27-2013 6:41 AM

 C# C# 

 1 Reply(s)
 1200  View(s)
Rate this:
Given a DateTime representing a person's birthday, how do I calculate their age?

Alex Leblois
Alex Leblois

Total Post:67

Posted on    December-27-2013 7:05 AM

Hi Chintoo,
You can calculate the age like this:

DateTime today = DateTime.Today;

int age = today.Year - bday.Year;

if (bday > today.AddYears(-age)) age--;

Don't want to miss updates? Please click the below button!

Follow MindStick