Re: interval output format available that removes ambiguity ? - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: interval output format available that removes ambiguity ?
Date
Msg-id 20040504174241.GA11199@wolff.to
Whole thread Raw
In response to interval output format available that removes ambiguity ?  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Responses Re: interval output format available that removes ambiguity ?  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
List pgsql-general
On Tue, May 04, 2004 at 12:24:37 +0200,
  Karsten Hilbert <Karsten.Hilbert@gmx.net> wrote:
> I have the need to output intervals (ages in this case).
> PostgreSQL takes great care to handle months correctly (eg
> take into account varying months lengths). This is only
> possible if either end point or start point of an interval are
> known. For post processing some of the ambiguity of what
> "2 mons" means would be removed if "61 days" was returned.

This is sort of done now, but the months part of the interval will be
treated as 30 days.

> Is there a way to tell PostgreSQL to return that type of
> interval (eg use weeks, days, hours, minutes, seconds, ...
> but not months and perhaps not even years [leap years, etc]) ?
> to_char(interval, text) doesn't work as it is applied after
> the fact.

You can extract "epoch" from the interval to get the total number of
seconds in the interval (converting months to the number of seconds
in 30 days) and then divide that by the appropiate amount.

pgsql-general by date:

Previous
From: David Wheeler
Date:
Subject: ANNOUNCE: Bricolage 1.8.0 Arrives!
Next
From: Manfred Koizar
Date:
Subject: Re: 7.4.2 Regression tests: test stats loops indefinately...