Re: Convert interval to hours

Поиск
Список
Период
Сортировка
От Steven Lembark
Тема Re: Convert interval to hours
Дата
Msg-id 20180914111050.16b7af88@steamer.attlocal.net
обсуждение исходный текст
Ответ на Re: Convert interval to hours  (Peter Kleiner <runtfan71@gmail.com>)
Ответы Re: Convert interval to hours
Список 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 по дате отправления:

Предыдущее
От: Peter Kleiner
Дата:
Сообщение: Re: Convert interval to hours
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Code of Conduct plan