I would strongly suggest you use parameterized queries instead of sending values as strings in the first place.
That way you only need to be able to convert your input format to DateTime
or DateTimeOffset
, and then you don't need to worry about the database format. This is not only simpler, but avoids SQL injection attacks (e.g. for string values) and is more robust in the face of database settings changes.
For the original conversion to a DateTime
, I suggest you use DateTime.ParseExact
or DateTime.TryParseExact
to explicitly specify the expected format.