Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id EC2609F958A for ; Sun, 16 Sep 2007 16:32:59 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 35683-04 for ; Sun, 16 Sep 2007 16:32:54 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from ns1.officenet.no (vpn.officenet.no [193.212.174.13]) by postgresql.org (Postfix) with ESMTP id 73ADC9F9629 for ; Sun, 16 Sep 2007 16:32:56 -0300 (ADT) Received: from [84.48.119.79] (helo=andreak-laptop.local) by ns1.officenet.no with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1IWzrN-0000vd-BV for pgsql-sql@postgresql.org; Sun, 16 Sep 2007 21:32:53 +0200 From: Andreas Joseph Krogh Organization: OfficeNet AS To: pgsql-sql@postgresql.org Subject: Re: Format intervall as hours/minutes etc Date: Sun, 16 Sep 2007 21:32:47 +0200 User-Agent: KMail/1.9.6 References: <200709161300.53257.andreak@officenet.no> <200709161327.16989.andreak@officenet.no> <6629.1189957316@sss.pgh.pa.us> In-Reply-To: <6629.1189957316@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200709162132.48124.andreak@officenet.no> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/120 X-Sequence-Number: 29333 On Sunday 16 September 2007 17:41:56 Tom Lane wrote: > Andreas Joseph Krogh writes: > > On Sunday 16 September 2007 13:14:27 Andreas Kretschmer wrote: > >> You can use extract(epoch, from ...) like this: > >> > >> test=3D*# select extract(epoch from '2007-09-22 17:00'::timestamp) - > >> extract (epoch from '2000-02-20 18:00'::timestamp); ?column? > >> ----------- > >> 239407200 > >> (1 row) > >> > >> Now you can calculate the hours and so on. > > > > Yes, this works fine for dates >=3D 1970, but I'm looking for a more > > general > > There's no particular restriction to dates after 1970 there. > > > solution which takes an arbitrary interval as input. > > Well, you could subtract the two timestamps and then "extract(epoch ...)" > the resulting interval, but I think you'll get the very same answer. > > [ pokes at it ... ] Hm, we seem to have an overflow problem in the > interval-to-epoch code for intervals exceeding 60-some years: > > regression=3D# select extract(epoch from '2007-09-22 17:00'::timestamp - > '1940-02-20 18:00'::timestamp); date_part > ------------ > 2132866800 > (1 row) > > regression=3D# select extract(epoch from '2007-09-22 17:00'::timestamp - > '1930-02-20 18:00'::timestamp); date_part > ------------- > -1846567696 > (1 row) > > Looks pretty trivial to fix ... Ok. =2D-=20 Andreas Joseph Krogh Senior Software Developer / Manager =2D-----------------------+---------------------------------------------+ OfficeNet AS | The most difficult thing in the world is to | Karenslyst All=C3=A9 11 | know how to do a thing and to watch | PO. Box 529 Sk=C3=B8yen | somebody else doing it wrong, without | 0214 Oslo | comment. | NORWAY | | Tlf: +47 24 15 38 90 | | =46ax: +47 24 15 38 91 | | Mobile: +47 909 56 963 | | =2D-----------------------+---------------------------------------------+