Skip site navigation (1) Skip section navigation (2)

Re: Adding to a date

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: Mike Ellsworth <younicycle(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Adding to a date
Date: 2008-06-30 22:02:58
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Mike Ellsworth wrote:
> 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;


Though there may be a better method for this. I'd need to poke around in 
the date arithmetic.


In response to


pgsql-novice by date

Next:From: Ridvan Lakas ng Bayan S. BaluyosDate: 2008-07-01 03:02:01
Subject: Slow Query and Big File Size even after emptying
Previous:From: Harold A. Giménez Ch.Date: 2008-06-30 21:52:56
Subject: Fwd: Adding to a date

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group