• Toreador (10/27/2010)


    Hugo Kornelis (10/27/2010)


    For the datetime data type, The only formats that are guaranteed to work correctly in all circumstances are:

    * yyyymmdd - for dates without time portion. No dashes. dots, slashes or other punctuation. The resulting datetime value will have its time portion set to midnight.

    We use yyyy-mm-dd which has always worked so far.

    Should I be worried?!

    set language German;

    select cast('2010-10-27' as datetime);

    select cast('20101027' as datetime);

    Die Spracheneinstellung wurde auf Deutsch geändert.

    -----------------------

    Msg 242, Level 16, State 3, Line 2

    Bei der Konvertierung eines char-Datentyps in einen datetime-Datentyp liegt der datetime-Wert außerhalb des gültigen Bereichs.

    -----------------------

    2010-10-27 00:00:00.000

    German was the first of the languages I tested that returned an error when using yyyy-mm-dd. I did not try the remaining languages. You can easily do that for yourself.

    (For a list of possible languages, run "select * from sys.syslanguages;", and use either the "name" or the "alias" column as argument for SET LANGUAGE).


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/