Best approach to remove time part of datetime in SQL Server

前端 未结 23 1608
南旧
南旧 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:29

    Strip time on inserts/updates in the first place. As for on-the-fly conversion, nothing can beat a user-defined function maintanability-wise:

    select date_only(dd)
    

    The implementation of date_only can be anything you like - now it's abstracted away and calling code is much much cleaner.

提交回复
热议问题