X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id C1593474E5C for ; Wed, 12 Feb 2003 10:24:28 -0500 (EST) Received: from wolff.to (wolff.to [66.93.249.74]) by postgresql.org (Postfix) with SMTP id 1320B474E44 for ; Wed, 12 Feb 2003 10:24:28 -0500 (EST) Received: (qmail 14372 invoked by uid 500); 12 Feb 2003 15:37:53 -0000 Date: Wed, 12 Feb 2003 09:37:53 -0600 From: Bruno Wolff III To: Plant Thomas Cc: pgsql-sql@postgresql.org Subject: Re: Sum of Intervals Message-ID: <20030212153753.GA14331@wolff.to> Mail-Followup-To: Plant Thomas , pgsql-sql@postgresql.org References: <418DEFFAA399D311818A00508B912F2883D74A@idefix.lvh.dnet.it> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <418DEFFAA399D311818A00508B912F2883D74A@idefix.lvh.dnet.it> User-Agent: Mutt/1.3.25i X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/242 X-Sequence-Number: 11640 On Wed, Feb 12, 2003 at 15:37:07 +0100, Plant Thomas wrote: > Hello, > > I'm trying to do a sum() of some time intervals. > I get the result as: '1 day 02:30' which is ok, but is there a function > which converts this to hours or do I have to write my own? > For example the '1 day 02:30' should become 26:30 hours. You can get the seconds using extract and then do further manipulation. To get fractional hours you can use the example below. To get hours and minutes you can use modular arithmatic and concatenate to build the desired string. area=> select extract(epoch from '1 day 02:30'::interval) / 3600; ?column? ---------- 26.5 (1 row)