Re: How to add days to date

From: Alban Hertroys <alban(at)magproductions(dot)nl>
To: "Alejandro Michelin Salomon ( Adinet )" <alejmsg(at)adinet(dot)com(dot)uy>
Cc: Pgsql-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to add days to date
Date: 2006-08-16 09:37:17
Message-ID: 44E2E74D.2030904@magproductions.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alejandro Michelin Salomon ( Adinet ) wrote:
> Hi:
>
> I have problem trying to add same days to a date.
>
> '2006-08-01' + FP.carencia + ( FP.prazo * ( MFP.parcela - 1 )) --> This
> results in
>
> EX :
> '2006-08-01' + 30 + ( 7 * ( 3 - 1 )) ==> '2006-08-01' + 44

Looks like you could use the interval type here too. I don't know what
the above is supposed to do, but I'd prefer to write it like:

'2006-08-01'::date + '1 month'::interval + (3-1) * '1 week'::interval

Or:
'2006-08-01'::date + INTERVAL '1 month' + (3-1) * INTERVAL '1 week'

It at least saves you the trouble of determining how long what month
takes, and it handles DST changes correctly.
The drawback is that it's not a linear data type, which can cause some
trouble if you need to convert values from your application to intervals.

For details, have a look at the documentation:
http://www.postgresql.org/docs/8.1/static/datatype-datetime.html

--
Alban Hertroys
alban(at)magproductions(dot)nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
7500 AK Enschede

// Integrate Your World //

In response to

Browse pgsql-general by date

  From Date Subject
Next Message MaXX 2006-08-16 10:15:57 Re: Partial indexes Vs standard indexes : Insert
Previous Message Julian Scarfe 2006-08-16 09:18:03 Timezones -- what comes out does not go in?