pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Steven Lembark <lembark@wrkhors.com>
To: pgsql-general@lists.postgresql.org
Cc: lembark@wrkhors.com
Subject: Re: Convert interval to hours
Date: Fri, 14 Sep 2018 11:10:50 -0500
Message-ID: <20180914111050.16b7af88@steamer.attlocal.net> (raw)
In-Reply-To: <CAP8Hi7Kt=r-pQbq5fnr-e029aLfX=ppyu+6mySxz_oe86LrMnA@mail.gmail.com>
References: <CAMBRECASE0aEf28DTVpY58MDrZVP9nUcTPW7NJkwPv4uVk-oAw@mail.gmail.com>
	<CAP8Hi7Kt=r-pQbq5fnr-e029aLfX=ppyu+6mySxz_oe86LrMnA@mail.gmail.com>

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




view thread (6+ messages)  latest in thread

Message-ID: <20180914111050.16b7af88@steamer.attlocal.net>
Permalink:  ../20180914111050.16b7af88@steamer.attlocal.net/
Also on:    postgresql.org/message-id/20180914111050.16b7af88@steamer.attlocal.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: lembark@wrkhors.com
  Subject: Re: Convert interval to hours
  In-Reply-To: <20180914111050.16b7af88@steamer.attlocal.net>
  References: <CAMBRECASE0aEf28DTVpY58MDrZVP9nUcTPW7NJkwPv4uVk-oAw@mail.gmail.com> <CAP8Hi7Kt=r-pQbq5fnr-e029aLfX=ppyu+6mySxz_oe86LrMnA@mail.gmail.com> <20180914111050.16b7af88@steamer.attlocal.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox