Search Postgresql Archives

Converting time interval to double precision of time unit

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

 



I'm using 8.3, and I'm trying to work with the interval type, and I
can't seem to get things right. I've been all over the docs[1,2], and
there is no mention on how this can be done.

While I can get:
SELECT '3 day 2 hour 34 minute'::interval

.. how can then get the fractional hours of this time interval in
double precision (or seconds, minutes, years, decades, etc.)?

Do I really need to extract the time subcomponents and do the math myself?

For example:
SELECT extract(day from interval)*24 + extract(hour from interval) +
extract(minute from interval)/60 as hours
FROM (SELECT '3 day 2 hour 34 minute'::interval) AS foo;

This seem like a bad hack, and I can't believe a function doesn't
already exist to properly cast a time interval to a fractional unit of
time, so I thought I'd check up to see if there is a better solution.

Thanks,

-Mike

[1] http://www.postgresql.org/docs/8.3/static/functions-datetime.html
[2] http://www.postgresql.org/docs/8.3/static/datatype-datetime.html

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[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