How do you update a DateTime field in T-SQL?

后端 未结 8 1703
我寻月下人不归
我寻月下人不归 2021-01-30 08:05

The following query does not update the datetime field:

update table
SET EndDate = \'2009-05-25\'
WHERE Id = 1

I also tried it with no dashes,

8条回答
  •  执笔经年
    2021-01-30 08:39

    When in doubt, be explicit about the data type conversion using CAST/CONVERT:

    UPDATE TABLE
       SET EndDate = CAST('2009-05-25' AS DATETIME)
     WHERE Id = 1
    

提交回复
热议问题