Wednesday, 21 August 2013

c# datetimepicker Validation

c# datetimepicker Validation

How to show a error message if the person is under 18 years old? I use the
following code, but it always displays that the age is invalid, even if I
enter a date earlier than 1995.
DateTime dt = DateTime.Parse(dob_main.Text);
DateTime dt_now = DateTime.Now;
DateTime dt_18 = dt.AddYears(-18);
if (dt.Date >= dt_18.Date)
{
MessageBox.Show("Invalid Birth Day");
}

No comments:

Post a Comment