Skip to content

Instantly share code, notes, and snippets.

@scinetic
Created March 8, 2014 22:32
Show Gist options
  • Save scinetic/9440022 to your computer and use it in GitHub Desktop.
Save scinetic/9440022 to your computer and use it in GitHub Desktop.
DateTime birthDay; // Declaring variable 'birthDay' of type 'DateTime'
if (DateTime.TryParse(Console.ReadLine(), out birthDay)) // Getting birthdate and initializing it to 'birthDay'
{
DateTime today = DateTime.Today; // Getting the current date
int age = today.Year - birthDay.Year; //Getting the age
if (birthDay > today.AddYears(-age)) age--; // Checking for accuracy of the age
Console.WriteLine(age); // Displaying the current age
Console.WriteLine(age + 10); // Displaying the age after 10 years
}
else
{
Console.WriteLine("Please enter the birthday in proper format (e.g. dd.mm.yyyy)");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment