How to set a DateTime variable in SQL Server 2008?

前端 未结 10 1908
暗喜
暗喜 2020-12-30 20:15

SQL Server 2008 is not doing what I expected with DateTime. It doesn\'t let me set DateTime variables, no matter what date format I use.

Wh

10条回答
  •  星月不相逢
    2020-12-30 21:09

    First of all - use single quotes around your date literals!

    Second of all, I would strongly recommend always using the ISO-8601 date format - this works regardless of what your locale, regional or language settings are on your SQL Server.

    The ISO-8601 format is either:

    • YYYYMMDD for dates only (e.g. 20110825 for the 25th of August, 2011)
    • YYYY-MM-DDTHH:MM:SS for dates and time (e.g. 2011-08-25T14:15:00 for 25th of AUgust, 14:15/2:15pm in the afternoon)

提交回复
热议问题