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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Check if string has valid DateTime format 1
Validate DateTime 3
SqlDateTime and DateTime 2
DateTime Span 6
Expand Range into List 2
DateTime 5
Nullable Dates 3
Checking for valid datetime 5

Back
Top