anyone know how to get the age based on a date(birthdate)
im thinking of something like this
string age = DateTime.Now.GetAccurateAge();
If you have a Instance Variable/Property that names DateOfBirth, you can use this method. Otherwise, you can pass the Date of Birth as a parameter for method. I made some calculus and I proved that never fails.
public int AgeCalc(){
DateTime now = DateTime.Now;
double age = Math.Floor((DateTime.Now - DateOfBirth).TotalDays)/((DateTime.IsLeapYear(year: now.Year)? 366 : 365));
return (age % 1) >= 0.951 ? Math.Round(age) : Math.Floor(age);
}
I hope that this can help you :)