Calculate age using C#.NET
Suppose user enter’s his date of birth that is in ‘mm/dd/yyyy’ format,
DateTime dob = Convert.ToDateTime(“08/03/1981”);
int years = DateTime.Now.Year – dob.Year;
dob = dob.AddYears(years);
if (DateTime.Now.CompareTo(dob) < 0)
int age = Years; // Output: Exact age.
No comments yet.