Re: interval output format available that removes ambiguity ?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: interval output format available that removes ambiguity ?
Date: 2004-05-05 14:10:37
Message-ID: 25609.1083766237@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert Treat 2004-05-05 14:13:30 Re: FYI, foxpro to postgresql conversion scripts
Previous Message Lonni Friedman 2004-05-05 13:42:04 vacuumdb is failing with NUMBER OF INDEX TUPLES NOT THE SAME AS HEAP