UPDATE t1
SET [Posting Date] = cast([Posting Date] as date)
WHERE cast([Posting Date] as time) > '00:00'
SQL datetime update time to 00:00:00 from all other time values
-
01-07-2022 - |
Question
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
OTHER TIPS
UPDATE t1
SET [Posting Date] = CAST([Posting Date] as DATE)
This may help you:
UPDATE tableName SET ColumnName = CAST( CAST( NOW( ) AS DATE ) AS DATETIME );
in sq-server
UPDATE [dbo].[1] SET [datetime]= CAST([datetime] AS DATE)
select * from [dbo].[1]
Try:
MODIFIEDDATETIME-(cast(MODIFIEDDATETIME as time))
This works for me:
update t1 set [Posting Date] = CONVERT(varchar,[Posting Date] , 112)
But I suposse it deppends heavily on how are the locale of your database configured, you could need to use another style (instead 112, perhaps 101 or 102...) see this link to see the possible style for the conversion and choose the one that suits you better.
Alternative if you need to do this once, you could change the column type to date, save and then back to datetime, but if the table is big this could be time consuming
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow