Re: How Many Years have Passed? - Mailing list pgsql-general

From Paul Wehr
Subject Re: How Many Years have Passed?
Date
Msg-id 3C224D9D.4030407@industrialsoftworks.com
Whole thread Raw
In response to How Many Years have Passed?  ("Ian Harding" <ianh@tpchd.org>)
List 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'spast my birthday), then doing date_part('year', foo) - date_part('year', bar) and adjusting for whether my birthday
haspassed? 
>
>Thanks!
>
>Ian A. Harding
>Programmer/Analyst II
>Tacoma-Pierce County Health Department
>(253) 798-3549
>mailto: iharding@tpchd.org
>



pgsql-general by date:

Previous
From: David Link
Date:
Subject: Re: sql scripts
Next
From: Stephan Szabo
Date:
Subject: Re: Can't use subselect in check constraint