Re: Converting time to float

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: Converting time to float
Дата
Msg-id 4631E588.2060902@archonet.com
обсуждение исходный текст
Ответ на Converting time to float  (Jorge Godoy <jgodoy@gmail.com>)
Ответы Re: Converting time to float
Список pgsql-general
Jorge Godoy wrote:
> Hi!
>
>
> I am needing to convert from TIME type to floats and taking 1h as the
> unit, so what I'd like is something that would allow me doing operations
> like:
>
> SELECT '00:10:00'::TIME / '1:00:00'::TIME;  -- Answer is: 0.16666666666666666667

But it doesn't make any sense to divide one time by another, does it?
Are you sure it's not intervals you want?

Anyway, try something like this:

SELECT extract(epoch from ('14:02:04'::time)) / extract(epoch from
('01:00:00'::time));
      ?column?
------------------
  14.0344444444444

The "epoch" is in seconds (from midnight 1970-01-01 for timestamps) so
gives you the result you want.

--
   Richard Huxton
   Archonet Ltd

В списке pgsql-general по дате отправления:

Предыдущее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: Vacuum-full very slow
Следующее
От: Jorge Godoy
Дата:
Сообщение: Re: Converting time to float