I need to validate that certain variables can create a valid datetime and if so make it otherwise ignore it without throwing an exception.
I have the following code
int y, m, d, h, mi, s, tz;
ogrFeature.GetFieldAsDateTime(field, out y, out m, out d, out h, out mi, out s, out tz);
fdr[fdrIndex++] = new DateTime(y, m, d, h, mi, s);
At the moment the construction of the date time will fail if (from MSDN)
year is less than 1 or greater than > 9999.
month is less than 1 or greater than> 12.
day is less than 1 or greater than the> number of days in month.
hour is less than 0 or greater than> 23.
minute is less than 0 or greater than> 59.
second is less than 0 or greater than> 59.
millisecond is less than 0 or greater> than 999.
I’ve had a look through and there doesn’t seem to be any specific methods to validate this kind of input.
Is there a nice way to validate this input without having to have a whole bunch of ifs or wrap it in a nasty try/catch and catch the ArgumentOutOfRangeException?
You can use this method: