tags:

views:

60

answers:

1

Hi, I'm trying to validate a date entered into text boxes like so using a custom validator:

string CombinedDate = String.Format("{0}-{1}-{2}", txtDay.Text, txtMonth.Text, txtYear.Text);

if (DateTime.TryParseExact(CombinedDate, "dd-MM-YYYY", DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out date))
{
    args.IsValid = true;
}
else
{
    args.IsValid = false;
}

but it fails for 21-02-2005 why is that? and how can i fix it

+6  A: 

YYYY must be yyyy

See here for other formats from MSDN

Arcturus