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

Home -> Community -> Usenet -> c.d.o.server -> Re: Calculating age of a person in PL/SQL

Re: Calculating age of a person in PL/SQL

From: David Fitzjarrell <oratune_at_msn.com>
Date: 6 Sep 2001 10:25:16 -0700
Message-ID: <32d39fb1.0109060925.3682d747@posting.google.com>


"Scott Mattes" <ScottMattes_at_yahoo.com> wrote in message news:<iYxl7.766$he4.819413_at_news1.news.adelphia.net>...
> If you just need the years old, how about
>
> select ( to_date( '01-aug-01' ) - to_date( '25-aug-1957', 'dd-mon-yyyy' ) )
> / 365 from dual;
>
> This gives 43.964384
>
> select ( to_date( '26-aug-01' ) - to_date( '25-aug-1957', 'dd-mon-yyyy' ) )
> / 365 from dual;
>
> and this gives 44.032877
>
> Add round() around it and you have years.
>
>
> "Hans Nesbø" <hans.nesboe_at_selmer.skanska.no> wrote in message
> news:9n5u8b$4nr$1_at_pippin.skanska.se...
> > Or you can:
> > select to_char(sysdate,'YYYY') - to_char(birth_date,'YYYY') from ........
> >
> > Best regards Hans
> >
> > "Randi Wølner" <randiwolner_at_hotmail.com> skrev i melding
> > news:9n4uc8$jnr$1_at_oslo-nntp.eunet.no...
> > > What is the most efficient way of calculating a person's age at a
> certain
> > > date?
> > > I have to create a PL/SQL function for doing it, and first I tried using
> > > MONTHS_BETWEEN and then dividing by 12,
> > > but the result will be wrong for the month of the persons's birthday..
> > >
> > > I guess someone has done something like this before - and hope you'll
> > > share..
> > >
> > > Thanks,
> > > Randi Wølner
> > >
> > >
> >
> >

TRUNC() provides the proper year, not ROUND().

David Fitzjarrell
Oracle Certified DBA Received on Thu Sep 06 2001 - 12:25:16 CDT

Original text of this message

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