Best approach to remove time part of datetime in SQL Server

前端 未结 23 1583
南旧
南旧 2020-11-21 22:51

Which method provides the best performance when removing the time portion from a datetime field in SQL Server?

a) select DATEADD(dd, DATEDIFF(dd, 0, getdate(         


        
23条回答
  •  北海茫月
    2020-11-21 23:23

    SELECT CAST(FLOOR(CAST(getdate() AS FLOAT)) AS DATETIME)
    

    ...is not a good solution, per the comments below.

    I would delete this answer, but I'll leave it here as a counter-example since I think the commenters' explanation of why it's not a good idea is still useful.

提交回复
热议问题