Let me start by saying that datetime has no concept of display format.
The display format is only relevant when we talk about the string representations of datetime values.
Then, lets take a look at the format you're using: yyyy-MM-dd HH:mm:ss
(known as ODBC canonical).
When converting strings of this format to DateTime
, the result of the conversion is culture dependent.
This means that when operating in some languages (like English) SQL Server will attempt to use yyyy-MM-dd
as date, but in other languages (like German) it will attempt to use yyyy-dd-MM
as date.
This is the the reason you get a conversion error.
Importent note: Unless you explicitly set the language (or DateFormat, for that matter), SQL Server will use the default language of the login - so for some users conversion might fail while for other users it will succeed.
Another note is that this problem only exists with DateTime
, but not with DateTime2
- converting this format to DateTime2
will always be interpreted as yyyy-MM-dd
.
So, considering all this information, you have three options here:
- Stop using DateTime, use DateTime2 instead.
- Instead of using the unsafe ODBC canonical format use the safe ISO8601 format whenever dealing with string representation of datetime values:
yyyy-mm-ddThh:mi:ss.mmm
.
- Explicitly set language or date format (to ymd) before your insert statement.
I would recommend combining the first two and avoid using the third if possible.
DateTime2
is a better data type than DateTime
, and ISO 8601 is the universal standard and is supported throughout different platforms and languages as an unambiguous datetime format.