How to convert an interval like “1 day 01:30:00” into “25:30:00”?

后端 未结 6 1477
无人及你
无人及你 2021-01-01 12:25

I need to add some intervals and use the result in Excel.

Since

sum(time.endtime-time.starttime)

returns the interval as \"1 da

6条回答
  •  Happy的楠姐
    2021-01-01 12:56

    It can be done, but I believe that the only way is through the following monstrosity (assuming your time interval column name is "ti"):

    select
                  to_char(floor(extract(epoch from ti)/3600),'FM00')
        || ':' || to_char(floor(cast(extract(epoch from ti) as integer) % 3600 / 60), 'FM00')
        || ':' || to_char(cast(extract(epoch from ti) as integer) % 60,'FM00')
        as hourstamp
    from whatever;
    

    See? I told you it was horrible :)

    It would have been nice to think that

    select to_char(ti,'HH24:MI:SS') as hourstamp from t
    

    would worked, but alas, the HH24 format doesn't "absorb" the overflow beyond 24. The above comes (reconstructed from memory) from some code I once wrote. To avoid offending those of delicate constitution, I encapsulated the above shenanigans in a view...

提交回复
热议问题