If you have a date, for example 06/12/78
How can you get the age of a person who is born on that date?
Printable View
If you have a date, for example 06/12/78
How can you get the age of a person who is born on that date?
Here's what I use to calculate the age in C#
Code:private int CalculateAge(string date)
{
DateTime d1 = Convert.ToDateTime(date);
int age;
if(DateTime.Now.Month < d1.Month || DateTime.Now.Month == d1.Month && DateTime.Now.Month < d1.Day)
age = DateTime.Now.Year - d1.Year - 1;
else
age = DateTime.Now.Year - d1.Year;
return age;
}