Create a program where you can enter your name and date of birth. You should then click on a button that should display a message containing your age.
Create a program where you can enter your name and date of birth. You should then click on a button that should display a message containing your age.
We have to consider that age is determined from the difference in years, and if the day of birth is greater than the current day, then subtract one unit:
Example: Birth on 10/01/1980
The best way to do this is what I found ( link ):
var birthdate = new DateTime(1980, 1, 10);
var today = new DateTime(2000, 1, 9);
var age = today.Year - birthdate.Year;
if (birthdate > today.AddYears(-age)) age--;