Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: SCRIPT: Get age of person in Years, Months, Days.

Re: SCRIPT: Get age of person in Years, Months, Days.

From: Craig & Co. <crb_at_amsa.gov.au>
Date: Fri, 18 Feb 2005 09:31:09 +1100
Message-ID: <42151b79$0$57510$c30e37c6@ken-reader.news.telstra.net>


"Michel Cadot" <micadot{at}altern{dot}org> wrote in message news:42142cbb$0$10013$626a14ce_at_news.free.fr...
>
>
> Why don't use Oracle built-in functions?
>
> For date_of_date enter in DD/MM/YYYY format:
>
> select

trunc(months_between(sysdate,to_date('&&date_of_birth','MM/DD/YYYY'))/12)
> || ' years ' ||
> mod(trunc(months_between(sysdate,
to_date('&&date_of_birth','MM/DD/YYYY'))),12)
> || ' months ' ||
> trunc(sysdate
> - add_months(to_date('&&date_of_birth','MM/DD/YYYY'),
> months_between(sysdate,
to_date('&&date_of_birth','MM/DD/YYYY'))))
> || ' days' "Year_Month_Day"
> from dual;
>
> Regards
> Michel Cadot
>
>

Thanks for that. That's a lot neater for the Years and Months, however, the days is wrong.

Using my birthday - 07-Apr-1975 - It comes up with 29 years 10 months and 10 days.
The Days should at least be 300+.
Hence the huge last statement in the program. I do like what you've done with the Years and Months though
and will change my program accordingly.

Cheers
Craig. Received on Thu Feb 17 2005 - 16:31:09 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US