0
Create a program where the user can enter his name and date of birth. Then click on a button that should display a message containing your age.
0
Create a program where the user can enter his name and date of birth. Then click on a button that should display a message containing your age.
7
We have to consider that age is determined from the difference in years, and if the day of birth is greater than the present day, then subtract a unit:
Example: Birth on 10/01/1980
The best way to do it I could think of (https://stackoverflow.com/a/1404/195417):
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--;
Browser other questions tagged c# winforms
You are not signed in. Login or sign up in order to post.
What did you do? What’s the question?
– novic
I did the graphical part only, put a Textbox, two Label "name" and "date of birth", a Button "Calculate Age", and a Datetimerpicker. Only that. My doubts are the commands to calculate the display age on the screen
– I.Muniiz
You have to enter the date (in your case choose) and at the time of calculation inform the number of years, by the current date?
– novic
Yeah, yeah, that’s right!
– I.Muniiz
change the title of your question, asked about years calculation of a date in C#
– novic
put the half response redirected with the comments.
– novic
and to appear in message format on the screen I put "Messagebox.Show("{0}");" that’s it?
– I.Muniiz
i did the editing.
– novic