Xaisoft Xaisoft - 1 year ago 86
SQL Question

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

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, but that does not work either.

Answer Source

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

   SET EndDate = CAST('2009-05-25' AS DATETIME)
 WHERE Id = 1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download