Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Program
- {
- public static void Main()
- {
- //get todays date and the birthdate
- DateTime today = DateTime.Today;
- DateTime birthday = new DateTime(1987,1,23);
- //calc difference in years
- int age = today.Year - birthday.Year;
- //Check to see if birthday has happened yet. If not adjust age down by 1
- if (birthday.DayOfYear > today.DayOfYear)
- age = age -1;
- //Display age on Console
- Console.WriteLine("Your current age is {0}.", age);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement