Round date to 10 minutes interval

后端 未结 7 2044
独厮守ぢ
独厮守ぢ 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:26

    Another method,

    select my_date - mod( (my_date-trunc(my_date))*24*60, 10)/24/60
    from (
      select sysdate my_date from dual
    );
    

    An alternative that might be quicker as it removes the call to trunc.

    select my_date - mod( (my_date-to_date('1970', 'yyyy'))*24*60, 10)/24/60
    from (
      select sysdate my_date from dual
    );
    
    0 讨论(0)
提交回复
热议问题