Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: SCRIPT: Get age of person in Years, Months, Days.
"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