Re: How Many Years have Passed?

From: Paul Wehr <postgresql(at)industrialsoftworks(dot)com>
To: Ian Harding <ianh(at)tpchd(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: How Many Years have Passed?
Date: 2001-12-20 20:44:13
Message-ID: 3C224D9D.4030407@industrialsoftworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Based on the lack of responses, I would say the short answer to your
question is "yes [that is the only way]".

The longer answer would be "are you sure that is what you want to do?"
I thought this would be an easy one, given the amout of time I spend
working with dates, but it turns out I've never really need to do it. I
have always either:

tested to see if a particular [conversational] age has come up:
can_vote=(today::date >= birth_date::date+'18 years'::interval);

or calculated a "biological" age, using a [relatively] fixed unit of
measure like days:
age='today'::date-birth_date::date;

what you are calculating, I would call "conversational age", in that
that is what we would say, if asked in conversation. For most
applications, I have found it to be of lower resolution (and lower
reproducibility) because of the varying length of years (even worse for
months, which is used as a basis of measurement more times than I care
to think about). This is also the same reason Postgres will not convert
an interval beween days, months and years.

You have probably already considered most of this, but it makes me feel
better to bring it up.

-paul

Ian Harding wrote:

>I have checked the FAQ and other sources and learned that the difference between two dates is the integer number of days. I want to know how many years are between those two dates.
>
>Is the only way to do that to do something like checking the julian day first to see if the second one is higher (i.e. it's past my birthday), then doing date_part('year', foo) - date_part('year', bar) and adjusting for whether my birthday has passed?
>
>Thanks!
>
>Ian A. Harding
>Programmer/Analyst II
>Tacoma-Pierce County Health Department
>(253) 798-3549
>mailto: iharding(at)tpchd(dot)org
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Carsten Grewe 2001-12-20 21:24:31 localization
Previous Message David Link 2001-12-20 19:48:22 Re: sql scripts