How do I convert an interval into a number of hours with postgres?

前端 未结 6 863
心在旅途
心在旅途 2020-11-28 22:31

Say I have an interval like

4 days 10:00:00

in postgres. How do I convert that to a number of hours (106 in this case?) Is there a function

6条回答
  •  臣服心动
    2020-11-28 22:37

    select floor((date_part('epoch', order_time - '2016-09-05 00:00:00') / 3600)), count(*)
    from od_a_week
    group by floor((date_part('epoch', order_time - '2016-09-05 00:00:00') / 3600));
    

    The ::int conversion follows the principle of rounding. If you want a different result such as rounding down, you can use the corresponding math function such as floor.

提交回复
热议问题