I need help handling the date format in SQL Server.
If you try the following, it will return the correct result:
SET LANGUAGE English SELECT CAST('2013-08-15' AS DATETIME)
This, however, will result in a conversion error, because, apparently, SQL Server interprets β8β as day and β15β as month:
SET LANGUAGE German SELECT CAST('2013-08-15' AS DATETIME)
I know that I can use a language-independent (slightly adapted ISO-8601) format YYYYMMDD (without a dash), and it will work in any language.
I donβt understand why YYYY-MM-DD is language dependent when it is clearly stated in SQL Books
"The interpretation depends on a combination of the string literal format, ... and the default language parameter settings ... Some of these string literals do not affect these parameters ... The ISO 8601 format is independent of these settings and is an international standard.
http://technet.microsoft.com/en-us/library/ms180878%28v=sql.105%29.aspx
Even if you look at the date format returned by select * from sys.syslanguages , it is not indicated - the date format is dmy , so it does not correspond to the ISO-8601 format.
So the questions are:
- Why is the ISO-8601 format dependent on the language, even if Books Online says otherwise?
- Where can I find the exact format used by SQL Server when parsing ISO-8601 dates?
UPDATE:
Further reading http://technet.microsoft.com/en-us/library/ms180878%28v=sql.105%29.aspx#ISO8601Format , he says: "To use the ISO 8601 format, you must specify each element in the format. This includes T, colons (:), + or -, and periods (.) '(For example, 2004-05-23T14: 25: 10).
The table above ( http://technet.microsoft.com/en-us/library/ms180878%28v=sql.105%29.aspx#StringLiteralDateandTimeFormats ) states that ISO 8601 Numeric is not dependent on DATEFORMAT, but is also not multilingual. I am not sure where to find additional information about the multilingual part, although, for example, the exact format used in each language.