N
needin4mation
Hi, this is what I did:
//this will work even though a decimal is returned because
//everyone will have a double digit age returned
//unless 9 and under or over 99 are in the database;
//can work to catch wrongly entered dates of birth;
//it is a given all ages must be two digits; there will
//never be otherwise in this scenario
DateTime dtThen = new DateTime ();
dtThen = Convert.ToDateTime(PerReader["dob"]);
DateTime dtNow = DateTime.Now;
TimeSpan ts = dtNow - dtThen;
double age = (ts.TotalDays / 365);
txtAge.Text = age.ToString().Substring(0,2);
Comments and improvements are welcome on how to get someone's age from
a date of birth in a database. Thanks!
//this will work even though a decimal is returned because
//everyone will have a double digit age returned
//unless 9 and under or over 99 are in the database;
//can work to catch wrongly entered dates of birth;
//it is a given all ages must be two digits; there will
//never be otherwise in this scenario
DateTime dtThen = new DateTime ();
dtThen = Convert.ToDateTime(PerReader["dob"]);
DateTime dtNow = DateTime.Now;
TimeSpan ts = dtNow - dtThen;
double age = (ts.TotalDays / 365);
txtAge.Text = age.ToString().Substring(0,2);
Comments and improvements are welcome on how to get someone's age from
a date of birth in a database. Thanks!