Re: Interval subtracting

From: "Milen A(dot) Radev" <milen(at)radev(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Interval subtracting
Date: 2006-02-18 14:45:34
Message-ID: 43F7330E.1060907@radev.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches pgsql-sql

Milorad Poluga написа:
> On Saturday 18 February 2006 15:24, Milen A. Radev wrote:
>> Milorad Poluga написа:
>>> Hi all,
>>>
>>> Is there something incorrect in the above query ?
>>> SELECT '10 years 1 mons 1 days'::interval - '9 years 10 mons 15 days'::interval
>>>
>>> ?column?
>>> ---------------
>>> 3 mons -14 days
>>>
>>> Why not '2 mons 16 days' ?
>>>
>>> /version = PostgreSQL 8.0.4 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3) /
>>
>> How many days are there in a month?
>>
>
> I beleive that a month is calculated on the 30-days base.

Are you sure? Where?

>
> One way to solve this problem is to use a neutal date element and make timestamps :
>
> SELECT age(('1990-01-01'::date + '10 years 1 mons 1 days'::interval)::timestamp ,
> ('1990-01-01'::date + '9 years 10 mons 15 days'::interval)::timestamp)
>
> age
> --------------
> 2 mons 16 days
>

Please read the last paragraph in section 8.5.1.4 of the manual
(http://www.postgresql.org/docs/8.1/static/datatype-datetime.html#AEN4775)
. It mentions the functions named "justify_days" and "justify_hours"
that could do what you need.

--
Milen A. Radev

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Joshua D. Drake 2006-02-18 15:15:15 Re: Blog post on EnterpriseDB...maybe off topic
Previous Message Thomas Hallgren 2006-02-18 14:43:24 Re: Pgfoundry and gborg: shut one down

Browse pgsql-patches by date

  From Date Subject
Next Message Peter Eisentraut 2006-02-18 16:15:41 Re: win codepages 1253, 1254, 1255, 1257 and cleanup
Previous Message Milorad Poluga 2006-02-18 14:36:20 Re: Interval subtracting

Browse pgsql-sql by date

  From Date Subject
Next Message ogjunk-pgjedan 2006-02-18 17:41:58 Need help: Find dirty rows, Update, Delete SQL
Previous Message Milorad Poluga 2006-02-18 14:36:20 Re: Interval subtracting