Re: format return of "age" to hh:mm

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: David Gauthier <davegauthierpg(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: format return of "age" to hh:mm
Date: 2020-03-05 16:19:31
Message-ID: CAKFQuwZxKkQZtxwu0i5jGp6aEU2B8SEkav9LweRKSwX9i6hUVA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Mar 5, 2020 at 8:50 AM David Gauthier <davegauthierpg(at)gmail(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2020-03-05 16:37:13 Re: format return of "age" to hh:mm
Previous Message Andrei Zhidenkov 2020-03-05 16:12:16 Re: format return of "age" to hh:mm