Search Postgresql Archives

Re: How to add days to date

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxx

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 //


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux