private bool ValidateMemberUnderage(DateTime dtBirthday, int nYears) { if (DateTime.Today.Year - dtBirthday.Year > nYears) return true; else if (DateTime.Today.Year - dtBirthday.Year == nYears) { DateTime dtBirthdayThisYear = dtBirthday.AddYears(nYears); if (DateTime.Today >= dtBirthdayThisYear) return true; else return false; } else return false; }
if (ValidateMemberUnderage(DateTime.Parse("1981-04-04"), 12) == false) { MessageBox.Show("Too Young"); } else { MessageBox.Show("Old Enough"); }
Last Updated on October 26, 2015