Re: format return of "age" to hh:mm - Mailing list pgsql-general

From David G. Johnston
Subject Re: format return of "age" to hh:mm
Date
Msg-id CAKFQuwZxKkQZtxwu0i5jGp6aEU2B8SEkav9LweRKSwX9i6hUVA@mail.gmail.com
Whole thread Raw
In response to format return of "age" to hh:mm  (David Gauthier <davegauthierpg@gmail.com>)
List pgsql-general
On Thu, Mar 5, 2020 at 8:50 AM David Gauthier <davegauthierpg@gmail.com> wrote: 
Hi:

How does one reformat the output of the "age" function to always be in terms of hours:mins.



Custom function.

Use justify_hours(interval) to normalize the input in terms of days
Use extract(field from interval) to get the components, including days
Multiply the days result by 24, add it to the hours result
Deal with fractional hours
Combine and return

There is no justify_minutes function unfortunately which, if implemented to the behavior of justify_hours, would do what you are looking for.  You basically want to write one, though I suspect in SQL instead of C.

David J.

pgsql-general by date:

Previous
From: Andrei Zhidenkov
Date:
Subject: Re: format return of "age" to hh:mm
Next
From: Adrian Klaver
Date:
Subject: Re: format return of "age" to hh:mm