Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 3/5/20 7:50 AM, David Gauthier wrote:
Hi:

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

E.g.

dvdb=> select age('2020-03-05 01:40:32-05','2020-03-01 21:56:05-05');
        age
-----------------
  3 days 03:44:27
(1 row)

I want...

"75:44"

I'm not married to "age"  If there's a better way to do this that's fine too.

Not sure it's better, but it will give you idea of what needs to be done:


SELECT
    floor(
        extract(
epoch FROM ('2020-03-05 01:40:32-05'::timestamptz - '2020-03-01 21:56:05-05'::timestamptz))
            / 3600)::varchar || ':' ||
    ((mod(
          extract(
epoch FROM ('2020-03-05 01:40:32-05'::timestamptz - '2020-03-01 21:56:05-05'::timestamptz))::numeric,
 3600::numeric) / 60)::int)::varchar;

?column?
----------
 75:44
(1 row)


Thanks in advance !


--
Adrian Klaver
adrian.klaver@xxxxxxxxxxx





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux