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

From Tom Lane
Subject Re: interval output format available that removes ambiguity ?
Date
Msg-id 25609.1083766237@sss.pgh.pa.us
Whole thread Raw
In response to Re: 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
Karsten Hilbert <Karsten.Hilbert@gmx.net> writes:
> I am now looking for a way to say:
>  select age('1999-2-2', '1999-3-2', without months);
>  select age('1999-5-2', '1999-6-2', without months);
> and get "28 days" in the first and "31 days" in the second
> result.

Just subtract the two timestamps (or dates) instead of using age().
Then you get an interval that has no month component.

> However, if you say that "1 mon" is always considered 30 days

He didn't say that.  He said that when the system *must* convert a
month-based interval to days and it has no date reference for it,
it uses 30 days.  Something like "now() + '1 month'::interval"
will do the "right thing".  This IMHO is the main application of
intervals with month components ...

            regards, tom lane

pgsql-general by date:

Previous
From: Lonni Friedman
Date:
Subject: vacuumdb is failing with NUMBER OF INDEX TUPLES NOT THE SAME AS HEAP
Next
From: Robert Treat
Date:
Subject: Re: FYI, foxpro to postgresql conversion scripts