Re: Convert interval to hours

From: Steven Lembark <lembark(at)wrkhors(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Cc: lembark(at)wrkhors(dot)com
Subject: Re: Convert interval to hours
Date: 2018-09-14 16:10:50
Message-ID: 20180914111050.16b7af88@steamer.attlocal.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 14 Sep 2018 11:55:18 -0400
Peter Kleiner <runtfan71(at)gmail(dot)com> wrote:

> On Fri, Sep 14, 2018 at 11:51 AM David Gauthier
> <davegauthierpg(at)gmail(dot)com> wrote:
> >
> > Hi:
> >
> > In perl/DBI, I have code that's getting me an "age" which returns
> > something like... "-17 days -08:29:35". How can I convert that to
> > a number of hours (as a float I would presume) ?

Suggest using one of the date modules. One issue is that not all
days are 86400s long: "leap second" is used to keep atomic clocks
in sync with siderial time so that telescopes report consistent
values over time. Catch is that simply dividing by 3600 doesn't
always work if the times fall across the wrong days.

You would normally want an integer for these rather than float
as the result to avoid rounding issues on extract or with comparisions
in or out of the database. You will normally not have more than one
second precision on times (timestamps are a different matter).

Q: What database are you using?

Postgres makes it easy enough to cast the values or compute the
difference is seconds.

--
Steven Lembark 3920 10th Ave South
Workhorse Computing Birmingham, AL 35222
lembark(at)wrkhors(dot)com +1 888 359 3508

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2018-09-14 16:23:50 Re: Code of Conduct plan
Previous Message Peter Kleiner 2018-09-14 15:55:18 Re: Convert interval to hours