Best approach to remove time part of datetime in SQL Server

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

    I would use:

    CAST
    (
    CAST(YEAR(DATEFIELD) as varchar(4)) + '/' CAST(MM(DATEFIELD) as varchar(2)) + '/' CAST(DD(DATEFIELD) as varchar(2)) as datetime
    ) 
    

    Thus effectively creating a new field from the date field you already have.

提交回复
热议问题