DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: calculate Age!!!

  1. #1
    Join Date
    Aug 2001
    Posts
    2
    Hai all!!

    I have one problem for my developing pace. To calculate the age.

    that is i give the my date of birth like 10-mar-1972
    find my age from sysdate.

    i.e sysdate - '10-mar-1972'

    thank you

  2. #2
    Join Date
    Jun 2000
    Location
    Madrid, Spain
    Posts
    7,447
    well how do you want it?

    In years, months and days?

  3. #3
    Join Date
    Aug 2001
    Location
    Waterloo, On
    Posts
    547
    Code:
    select round(months_between(sysdate, to_date('10-Mar-1972', 'dd-Mon-yyyy'))/12)
    from dual
    /

    Raminder Singh

    Oracle Certified DBA: Oracle 8i, 9i


    Mail me at raminderahluwalia@rediffmail.com.

  4. #4
    Join Date
    Aug 2001
    Location
    Waterloo, On
    Posts
    547
    Below is a function I created for calculating age in years and months.

    Code:
    create or replace function age(dob in date)
    return varchar2
    as
    yrs number(3);
    mnths number(2);
    str varchar2(20);
    Begin
    yrs:=floor(months_between(sysdate, dob)/12);
    mnths:=mod(months_between(sysdate, dob),12);
    str:=yrs||' Years '||mnths||' Months';
    return str;
    end; 
    /

    Raminder Singh

    Oracle Certified DBA: Oracle 8i, 9i


    Mail me at raminderahluwalia@rediffmail.com.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width