1
2
3
4
5
6
7
8
9
10
11
12
|
/// <summary>
/// Gets the age of eg. a person from its birthday.
/// </summary>
/// <param name="birthday">The birthday.</param>
/// <returns>The age in years.</returns>
public static int GetAgeFromDate(DateTime birthday)
{
int years = DateTime.Now.Year - birthday.Year;
birthday = birthday.AddYears(years);
if (DateTime.Now.CompareTo(birthday) < 0) { years--; }
return years;
}
|