将日期截断为仅小时/分钟
我如何像这样截断 sql server 2008 中的日期:
How do i trunc the date in sql server 2008 like this :
我有 2012-01-02 12:04:11.443
我只想选择 2012-01-02 12:00:00.000
和 2012-01-02 12:04:00.000
(小时和分钟级别)
I have 2012-01-02 12:04:11.443
and I want only to select 2012-01-02 12:00:00.000
and 2012-01-02 12:04:00.000
(hour and minute level)
推荐答案
declare @D as datetime = '2012-01-02T12:04:11.443'
select dateadd(hour, datediff(hour, 0, @D), 0)
select dateadd(minute, datediff(minute, 0, @D), 0)
相关文章