Re: Convert interval to hours - Mailing list pgsql-general

From Steven Lembark
Subject Re: Convert interval to hours
Date
Msg-id 20180914111050.16b7af88@steamer.attlocal.net
Whole thread Raw
In response to Re: Convert interval to hours  (Peter Kleiner <runtfan71@gmail.com>)
Responses Re: Convert interval to hours  (Ron <ronljohnsonjr@gmail.com>)
List pgsql-general
On Fri, 14 Sep 2018 11:55:18 -0400
Peter Kleiner <runtfan71@gmail.com> wrote:

> On Fri, Sep 14, 2018 at 11:51 AM David Gauthier
> <davegauthierpg@gmail.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@wrkhors.com                                    +1 888 359 3508


pgsql-general by date:

Previous
From: Peter Kleiner
Date:
Subject: Re: Convert interval to hours
Next
From: "David G. Johnston"
Date:
Subject: Re: Code of Conduct plan