How to set a DateTime variable in SQL Server 2008?

前端 未结 10 1883
暗喜
暗喜 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 20:51

    Just to explain:

    2011-02-15 is being interpreted literally as a mathematical operation, to which the answer is 1994.

    This, then, is being interpreted as 1994 days since the origin of date (Jan 1st 1900).

    1994 days = 5 years, 6 months, 18 days = June 18th 1905

    So, if you don't want to to the calculation each time you want compare a date to a particular value use the standard: Compare the value of the toString() function of date object to the string like this :

    set @TEST  ='2011-02-05'
    

提交回复
热议问题