RP wrote:
Did something like this:
--------------------------------------------------------------------
DateTime myDate = txtDOB.Text;
int myYear = myDate.Year;
int PresentYear = DateTime.Now.Year;
txtAge.Text = (PresentYear - myYear);
----------------------------------------------------------------------
Please correct.
What about the code doesn't do what you want?
The one thing that jumps out to me is that if you are really looking for
a calculation of "age", then the above doesn't take into account the
rest of the date. Is that your concern?
If so, then something like this might work for you:
DateTime myDate = DateTime.Parse(txtDOB.Text),
dateNow = DateTime.Now;
int cyearsAge = dateNow.Year - myDate.Year;
myDate = myDate.AddYears(cyearsAge);
if (myDate dateNow)
{
cyearsAge--;
}
txtAge.Text = cyearsAge.ToString();
Pete