SQLDateTime Exception Handling


i have a method for calculating dates. The date string is commited as a string, or as a date. If i commit the date as a string, i use SQLDateTime to convert it to a date variable. But the exception handling seems to be strange to me.
F.e. when i commit a date string like “2014-06-04 08:30:10” everything works fine. When i try to get it into an exception with “2014-06-04 27:30:10” the date variable will be: “2014-06-05 03:30:10”. The time of day “27:30” does not really exist, but SQLDateTime adds it to the next day. I have expected an UnsupportedFormatException.
Next example: If i commit a “xxx2014-06-04 08:30:10”, i get this date: “1601-01-04 8:30:10”. I have expected an exception again.

Is there a way to get the SQLDateTime crash with wrong dates?


I don’t believe there is; unexpected values are treated as the earliest value that it’s possible to have, and unexpected values are changed to expected ones. Your 27th hour is an interesting example; it’s actually quite useful for when you’re adding hours to times, or want to find the last Saturday in the month (which is actually the zeroth Saturday in the next month), and so on.

You’ll need to use a RegEx to validate your dates before saving - it’s a better way of catching things than asking SQL to do it for you.