Check if DateTime is valid

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

Is there a way to check if a day, month and year values create a valid
date?

I am using the following:

try {
DateTime start = new DateTime(o.StartYear, o.StartMonth,
o.StartDay);
}
catch {
return new ValidationFailure("StartDate", "Seleccione a data
inicial");
}
return null;

Can I have do this check without using try/catch and not firing an
exception?

Thank You,
Miguel
 
Is there a way to check if a day, month and year values create a valid
date?

I am using the following:

try {
DateTime start = new DateTime(o.StartYear, o.StartMonth,
o.StartDay);
}
catch {
return new ValidationFailure("StartDate", "Seleccione a data
inicial");
}
return null;

Can I have do this check without using try/catch and not firing an
exception?

You could concatenate a string and use DateTime.TryParse.

You could implement the necessary logic yourself.

Arne
 
Back
Top