Skip to content

Instantly share code, notes, and snippets.

@sir4ju1
Created April 25, 2014 09:47
Show Gist options
  • Save sir4ju1/11283960 to your computer and use it in GitHub Desktop.
Save sir4ju1/11283960 to your computer and use it in GitHub Desktop.
Calculate someone's age in C#
public int CalculateAge(Datatime bday)
{
DateTime today = DateTime.Today;
int age = today.Year - bday.Year;
if (bday > today.AddYears(-age)) age--;
return age;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment