Round date to 10 minutes interval

后端 未结 7 2038
独厮守ぢ
独厮守ぢ 2021-02-19 07:26

I have a DATE column that I want to round to the next-lower 10 minute interval in a query (see example below).

I managed to do it by truncating the seconds

7条回答
  •  执笔经年
    2021-02-19 08:24

    select
      trunc(sysdate, 'mi')
      - numtodsinterval(mod(EXTRACT(minute FROM cast(sysdate as timestamp)), 10), 'minute')
    from dual;
    

    or even

    select
      trunc(sysdate, 'mi')
      - mod(EXTRACT(minute FROM cast(sysdate as timestamp)), 10) / (24 * 60)
    from dual;
    

提交回复
热议问题