Rounding milliseconds in T-SQL

In SQL Server 2008 , I have the following column of type DateTime in a table.

 +-------------------------+ | LTime | +-------------------------+ | 2009-12-07 10:40:21.893 | | 2009-12-07 10:42:18.173 | +-------------------------+ 

In the above column, I want to select DateTime and round milliseconds to get the bottom output

 +---------------------+ | LTime | +---------------------+ | 2009-12-07 10:40:22 | | 2009-12-07 10:42:18 | +---------------------+ 

Thank you all for your help.

+6
source share
1 answer

whether

 SELECT CAST('2009-12-07 10:40:21.893' AS DATETIME2(0)), CAST('2009-12-07 10:42:18.173' AS DATETIME2(0)) 

Do what you need?

+12
source

Source: https://habr.com/ru/post/887148/


All Articles