Search Postgresql Archives

Re: Converting time to float

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux