Re: Get interval in months

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-general(at)postgresql(dot)org
Cc: Gerhard Heift <ml-postgresql-20081012-3518(at)gheift(dot)de>
Subject: Re: Get interval in months
Date: 2008-11-08 12:59:37
Message-ID: 20081108125937.GA9668@tux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Gerhard Heift <ml-postgresql-20081012-3518(at)gheift(dot)de> schrieb:

> Hello,
>
> I want to get an interval in months from two dates:
>
> SELECT '2008-02-01'::timestamp - '2008-01-01'::timestamp AS '1 month'
>
> Here I want '1 month' and not '31 days' as answer.

How long is a month? 28 days? 31 days? But okay, i will try:

test=*# SELECT justify_days('2008-02-01'::timestamp - '2008-01-01'::timestamp) ;
justify_days
--------------
1 mon 1 day
(1 row)

Is this okay for you? PostgreSQL assume 30 days per month.

Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Kretschmer 2008-11-08 13:01:13 Re: grant privileges
Previous Message David Spadea 2008-11-08 12:44:45 Re: Get interval in months