Created
April 25, 2014 09:47
-
-
Save sir4ju1/11283960 to your computer and use it in GitHub Desktop.
Calculate someone's age in C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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