Den här funktionen beräknar åldern för en person:
public int Age(DateTime born) {
DateTime today = DateTime.Today;
int age = today.Year - born.Year;
if (today.Month < born.Month || (today.Month == born.Month && today.Day < born.Day)) {
age--;
}
return age;
}
Exempel:
int age = Age(new DateTime(1952,3,11))