Skip site navigation (1) Skip section navigation (2)

Regarding interval conversion functions and a seeming lack of usefulness

From: Bill Moran <wmoran(at)collaborativefusion(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Regarding interval conversion functions and a seeming lack of usefulness
Date: 2008-02-27 14:47:49
Message-ID: 20080227094749.f69e36be.wmoran@collaborativefusion.com (view raw or flat)
Thread:
Lists: pgsql-general
This has come up a few times over the last few months, and I'm not
too keen on the solutions we've been using.

There seems to be a lack of useful functions for converting intervals
to useful representations.  For example, I want to display an interval
in hours and fractions of hours only, not hours and minutes.  There
are lots of examples of when certain representations are more appropriate
than others (think pregnancy terms, why on earth is the woman never
pregnant for 3 months?  It's always 12 weeks!)

Anyway, rant aside, I can't seem to find anything to do this in PG.
I could write a stored procedure easily enough, but I want to make
sure I'm not reinventing the wheel first (I find it hard to believe
I'm the first person ever wanting to do this!)

Something like:
$ SELECT CONVERT('12 days 13 hours'::INTERVAL AS hour);
 hour
------
   301
$ SELECT CONVERT('6 hours 17 minutes'::INTERVAL AS hour);
 hour
------
6.2833

Am I approaching this problem wrong? or is there something out there
and my Google skills are lacking?

-- 
Bill Moran
Collaborative Fusion Inc.
http://people.collaborativefusion.com/~wmoran/

wmoran(at)collaborativefusion(dot)com
Phone: 412-422-3463x4023

Responses

pgsql-general by date

Next:From: Magnus HaganderDate: 2008-02-27 14:50:07
Subject: Re: PostgreSQL-installation-problem on Windows XP Home edition
Previous:From: Richard HuxtonDate: 2008-02-27 14:41:09
Subject: Re: PostgreSQL-installation-problem on Windows XP Home edition

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group