Search code examples
sqlsql-server-2008t-sqldatetimemilliseconds

SQL datetime update time to 00:00:00 from all other time values


Is there a way to update all columns in table from

2010-12-31 23:59:59.000

to

2010-12-31 00:00:00.000

Something like this??

UPDATE t1
SET [Posting Date] = [Posting Date] with ms = 00:00:00.000
WHERE ms = other than 00:00:00.000
GO

Solution

  • UPDATE t1
    SET [Posting Date] = cast([Posting Date] as date)
    WHERE cast([Posting Date] as time) > '00:00'