Rounding a datetime value down to the nearest half hour

前端 未结 6 574
再見小時候
再見小時候 2021-01-11 13:11

I have a requirement to round a datetime2 value down to the nearest half hour. For example \'10/17/2013 12:10:00.123\' would round down to \'10/17/2013 12:00:00.0\' And \'10

6条回答
  •  说谎
    说谎 (楼主)
    2021-01-11 14:08

    Here is one way to do it:

    update t set
      d = dateadd(minute,datediff(minute,'19000101',d)/30*30,'19000101');
    

提交回复
热议问题