1)HOW TO CALCULATE AGE AFTER USER ENTER,S HIS DOB IN TEXTBOX?
2)HOW TO SUBTRACT BIRTH YEAR WITH CURRENT YEAR.?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Dec 2, 2012, 2:24 PM
DateTime dateBorn;
bool isValid = DateTime.TryParse(textBox1.Text, out dateBorn);
if (isValid && dateBorn <= DateTime.Today)
{
label1.Text = age.ToString();
int yearDiff = today.Year - dateBorn.Year;
label2.Text = yearDiff.ToString();
}
else
{
MessageBox.Show("Textbox doesn't contain a valid date of birth. Please amend");
textBox1.Focus();
return;
}