How to select date without time in SQL

后端 未结 17 2121
灰色年华
灰色年华 2020-11-28 20:09

When I select date in SQL it is returned as 2011-02-25 21:17:33.933. But I need only the Date part, that is 2011-02-25. How can I do this?

17条回答
  •  暖寄归人
    2020-11-28 21:00

    The fastest is datediff, e.g.

    select dateadd(d, datediff(d,0, [datecolumn]), 0), other..
    from tbl
    

    But if you only need to use the value, then you can skip the dateadd, e.g.

    select ...
    WHERE somedate <= datediff(d, 0, getdate())
    

    where the expression datediff(d, 0, getdate()) is sufficient to return today's date without time portion.

提交回复
热议问题