Truncate Datetime to Second (Remove Milliseconds) in T-SQL

后端 未结 8 1499
庸人自扰
庸人自扰 2020-12-01 08:59

What is the best way to shorten a datetime that includes milliseconds to only have the second?

For example 2012-01-25 17:24:05.784 to 2012-01-25

8条回答
  •  情话喂你
    2020-12-01 09:30

    The fastest, also language safe and deterministic

    DATEADD(second, DATEDIFF(second, '20000101', getdate()), '20000101')
    

提交回复
热议问题