public static Int32 GetAge(this DateTime dateOfBirth) { var today = DateTime.Today; var a = (today.Year * 100 + today.Month) * 100 + today.Day; var b = (dateOfBirth.Year * 100 + dateOfBirth.Month) * 100 + dateOfBirth.Day; return (a - b) / 10000; }
var now = float.Parse(DateTime.Now.ToString("yyyy.MMdd")); var dob = float.Parse(dateOfBirth.ToString("yyyy.MMdd")); var age = (int)(now - dob);
Source: http://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c
Last Updated on October 26, 2015