X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E48093A19BF for ; Sun, 2 Jan 2005 16:52:19 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 26576-08 for ; Sun, 2 Jan 2005 16:52:10 +0000 (GMT) Received: from md1.psixpress.com (md1.psixpress.com [154.32.105.205]) by svr1.postgresql.org (Postfix) with ESMTP id EB1DA3A2C0C for ; Sun, 2 Jan 2005 16:52:08 +0000 (GMT) Received: from kaufbach.delug.de (108.pool1.dialup.cybernet-ag.de [195.143.124.108]) by md1.psixpress.com (MOS 3.5.6-GR) with ESMTP id CIM74963 (AUTH via LOGINBEFORESMTP); Sun, 2 Jan 2005 16:52:06 GMT Received: from kretschmer by kaufbach.delug.de with local (Exim 3.35 #1) id 1Cl8sW-00027i-00 for pgsql-sql@postgreSQL.org; Sun, 02 Jan 2005 17:46:52 +0100 Date: Sun, 2 Jan 2005 17:46:52 +0100 From: Kretschmer Andreas To: List pgsql-sql Subject: Re: Formatting an Interval Message-ID: <20050102164652.GA8118@kaufbach.delug.de> References: <238e52230412310837183fb730@mail.gmail.com> <20041231194118.GA23987@winnie.fuhr.org> <1104682763.3610.2.camel@petra> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1104682763.3610.2.camel@petra> User-Agent: Mutt/1.3.28i X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.056 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200501/5 X-Sequence-Number: 19793 am Sun, dem 02.01.2005, um 17:19:23 +0100 mailte Karel Zak folgendes: > > You could write a function to format the interval. For example, > > with PL/pgSQL you could use EXTRACT(epoch FROM interval_value) to > > convert the interval to a number of seconds; convert that to hours, > > minutes, and seconds; and use TO_CHAR to format the return value. > > to_char() works with standard date/time ranges, for example 1-24 -- so > there is no way how convert to anything like "31:57:52". Read again. Extract the seconds and calculate the hours, minutes and seconds. test_db=# select extract (epoch from '1 day 07:57:52'::interval); date_part ----------- 115072 (1 Zeile) Okay, 115072 Seconds. test_db=# select extract (day from '1 day 07:57:52'::interval); date_part ----------- 1 (1 Zeile) Okay, this is 1 day, 24 hours. test_db=# select extract (epoch from '1 day 07:57:52'::interval) - 60*60*24*(extract (day from '1 day 07:57:52'::interval)); ?column? ---------- 28672 (1 Zeile) Okay, 24 hours and 28672 seconds, and you know, this is less then 1 day. Now calculate, how many hours in 28672 seconds: test_db=# select 28672 / 3600; ?column? ---------- 7 (1 Zeile) Now you can add 24 hours and 7 hours, the remainder is test_db=# select 28672 - 3600*7; ?column? ---------- 3472 (1 Zeile) seconds. Now you can calculate the minutes and, finaly, the seconds. Is the way now okay? Write a function for this job. Regards, Andreas -- Diese Message wurde erstellt mit freundlicher Unterstützung eines freilau- fenden Pinguins aus artgerechter Freilandhaltung. Er ist garantiert frei von Micro$oft'schen Viren. (#97922 http://counter.li.org) GPG 7F4584DA Was, Sie wissen nicht, wo Kaufbach ist? Hier: N 51.05082°, E 13.56889° ;-)