Re: Adding to a date

From: "Mike Ellsworth" <younicycle(at)gmail(dot)com>
To: "Steve Crawford" <scrawford(at)pinpointresearch(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Adding to a date
Date: 2008-07-02 13:40:37
Message-ID: 219951fd0807020640w448cef25h42b3ebfe7ca4b41b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

>> I was beginning to create some financial functions for calculating
>> Future Values, PV's, etc...
>>
>> I'm hoping there is a way to:
>> 1) Date of birth + xx years - with a result of date (Result 1)
>> 2) Subtract now or an assumed date from Result 1 to get Result 2
>>
>
> Problems like 1 and 2 are easy - use "intervals".
>
> select '1943-06-30'::date + '65 years'::interval;
> 2008-06-30 00:00:00
>
> select current_date + '65 years'::interval;
> 2073-06-30 00:00:00
>
>
>> 3) Divide by ~ 365.25 for years, which would be 'periods' in the function.
>>
>
> select ('2008-06-30'::date - '1943-06-30'::date)/365.25;
>
> 65.0020533880903491
>
> Though there may be a better method for this. I'd need to poke around in the
> date arithmetic.
>

Here's what I came up with. We're trying to make this simple for
users, so we'll need to simplify the date & interval (periods) portion
of the FVPMT function a little .. but this works.
SELECT
ages.dob AS ages_dob, to_char(greatest(round(FVPMT(ages.annual*.04,
.06, (((ages.dob + interval '65 years')::date)- date
'7/1/2008')/365.25)),0), '$FMG999,999') AS fv, ages.annual AS
annual_wage
FROM
"test"."ages"

Thanks for the help from all.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message A B 2008-07-02 13:52:23 encoding problem when creating a database
Previous Message Netzach 2008-07-02 10:21:01 Calculating repeating events - functionality lost with the demise of tinterval ?