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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Dec 2, 2012, 9:24 AM EST
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;
}