Query to calculate age

Hi
Please suggest me to wirte a function which can calculate age.

Hi,
No need of function. Just simple calculation.
SQL> select round(months_between(sysdate,to_date('11-MAY-1977','dd-MON-YY'))/12) age from dual;
       AGE
        33If you are taking in account the dates stored in a date column of oracle table then do take care of the years
before and after 1950.
A thread for your reference: Re: date airthmetic

Similar Messages

  • How to calculate Age in BEx query

    Hi,
    I need to calculate age in years based on person's date of birth and the key date that user of the report will enter.
    So, basically in my query I already have date of birth characteristic from 0PERSON InfoObject. I created ZAGE key figure and added it to the query that I would like to populate with person's age.
    So I know I have to enter some code in CMOD for calculated key figure ZAGE to get calculated based on birthdate and key date that user enters. Can somebody help with the code?
    thanks

    Hi,
    The variable should be in "Date" dimension. I have missed one important information in earlier mail.
    The processing type of the variable (user entry date) should be of "Customer Exit' and dimension (in last tab) should be "Date".
    By selecting this dimension, the variable input help screen also appears in calendar format to help user to select date instead of writing it in variable input.
    No need to write any custom code for this variable. We are selecting the "Customer exit" processing type to get Date dimension. In Normal user entry variables we can't get date & time dimension.
    "Ready for Input" should be selected so that user can enter date.
    I hope you can solve your issue now.
    Thanks for your feedback.
    Regards,
    Arun Thangaraj.
    Edited by: Arun  Thangaraj on Oct 8, 2008 8:48 AM

  • How to calculate age in oracle

    Hi,
    T was trying do calculate age as on todays date in ORACLE but after a lot of brain storming i didn't get it.
    Kindly tell me how to calculate age as in years month days.
    For ex.. My DOB- 02-feb-1984 so my age should get as 27 Years 2 months 8 days
    How to do it.
    I tried this
    select
    TRUNC( months_between( sysdate, TO_DATE('02-02-1984','DD-MM-YYYY') )/12 ) Year,
    TRUNC( mod(months_between( sysdate, TO_DATE('02-02-1984','DD-MM-YYYY') ),12) ) Month,
    mod(months_between( sysdate, TO_DATE('02-02-1984','DD-MM-YYYY') ),12) /30 Days
    from dual
    but days are not calculating correctly...
    RGds,
    PC

    sorry..i didn't chck your query..it is right but give wrong answer..
    WITH got_months AS
         SELECT     TO_DATE('02-02-1984','DD-MM-YYYY')
         ,     FLOOR (MONTHS_BETWEEN (SYSDATE, TO_DATE('02-02-1984','DD-MM-YYYY')))     AS months
         FROM     dual
    SELECT     TO_DATE('02-02-1984','DD-MM-YYYY')
    ,     TO_CHAR (FLOOR (months / 12))     || ' years, '     ||
         TO_CHAR (MOD (months, 12))      || ' months, '     ||
         TO_CHAR ( CEIL ( SYSDATE
              - ADD_MONTHS ( TO_DATE('02-02-1984','DD-MM-YYYY')
                        , months
              )               || ' days'
    FROM got_months
    o/p
         TO_DATE('02-02-1984','DD-MM-YY     TO_CHAR(FLOOR(MONTHS/12))||'YE
    1     2/2/1984     27 years, 7 months, 9 days
    1 day more..1     it sud be.. 2/2/1984     27 years, 7 months, 8 days
    if i make correction with add_months like below..
    WITH got_months AS
         SELECT     TO_DATE('02-02-1984','DD-MM-YYYY')
         ,     FLOOR (MONTHS_BETWEEN (SYSDATE, TO_DATE('02-02-1984','DD-MM-YYYY')))     AS months
         FROM     dual
    SELECT     TO_DATE('02-02-1984','DD-MM-YYYY')
    ,     TO_CHAR (FLOOR (months / 12))     || ' years, '     ||
         TO_CHAR (MOD (months, 12))      || ' months, '     ||
         TO_CHAR ( CEIL ( SYSDATE
              - ADD_MONTHS ( TO_DATE('02-02-1984','DD-MM-YYYY')
                        , months
                        )-1
              )               || ' days'
    FROM got_months
    then o/p is..
         TO_DATE('02-02-1984','DD-MM-YY     TO_CHAR(FLOOR(MONTHS/12))||'YE
    1     2/2/1984     27 years, 7 months, 8 days
    correct but cdnt understand why sud -1?

  • Function Module to calculate age

    Hi Abapers,
    Kindly suggest some function module which can calculate age of a person by taking date of birth till date.
    Thanks in advance,
    Radhika

    Hi Radhika,
    Check this program
    REPORT ZTEST.
    DATA : BIRTH_DATE LIKE SY-DATUM,
           DAYS TYPE NUM2,
           MONTHS TYPE NUM2,
           YEARS TYPE NUM2.
    BIRTH_DATE = '19830307'.
    CALL FUNCTION 'HRCM_TIME_PERIOD_CALCULATE'
      EXPORTING
        BEGDA         = BIRTH_DATE
        ENDDA         = SY-DATUM
      IMPORTING
        NOYRS         = YEARS
        NOMNS         = MONTHS
        NODYS         = DAYS
      EXCEPTIONS
        INVALID_DATES = 1
        OVERFLOW      = 2
        OTHERS        = 3.
    WRITE : / YEARS , 'years' , MONTHS , 'months' , DAYS , 'days'.
    Regards,
    Satish

  • ABAP-HR MODULE(HOW TO CALCULATE AGE & YEARS OF SERVICE)

    HI,
    HOW TO CALCULATE AGE & YEARS OF SERVICE means for example
    I AM USING PNPCE LDB.
    (1) whose age is greater than 52.833 years with 7.833 years of service, with annual rate of pay $170,000 or more, or
    (2) age plus employment service is 65 or more, with annual rate of pay of $ 170,000 or more.
    Note that the $ 170,000 parameter would be a variable that could change annually when this report would be generated. In the past, age and service value were determined as of the run date. The determination date would also be a variable that would change when the report would be generated.
    Thanks&Regards
    Rahul.

    Hi Rahul,
    This is the 2nd warning !!! Please... use the correct or most appropriate forum.
    The ABAP Objects Forum should be used for: ABAP Object definition and implementation including encapsulation, interfaces and inheritance in ABAP Objects.
    This thread will be moved from to .
    You're asking this question in two thread, so the duplicated thread will be deleted.
    Please have a look at [Forum Rules of Engagement|https://wiki.sdn.sap.com/wiki/display/HOME/RulesofEngagement] before posting.
    Also read this thread Welcome and Rules of Engagement.
    Greetings,
    Marcelo Ramos

  • How to Calculate AGE by getting difference between two Date Fields

    HI Gems
    I need to calculate AGE from getting difference from two date fields. But when i am trying to wrte fromula as Current date - date1(some date field) then it is showing error.
    How can i get values.
    Thanks
    Manu

    You already asked this question:
    How to calculate AGE from two different date fields

  • How to calculate AGE from two different date fields

    hi
    I need to calculate AGE from two different date fields.
    Can some help me how to do, when i try to do substraction formula it is showing error.
    Thank You
    Manu

    Manu wrote:
    Hi
    Both fields are in date format only, i need to calculate no . of days between two different dates
    Thanks
    ManuThe reason for the question about the format of the column is because the simplest solution only works on DATE columns. Others have mentioned this here, but if you want the difference between two date fields, you can use this formula:
    TIMESTAMPDIFF(SQL_TSI_DAY, date_column1, date_column2)
    The above being said, you still didn't tell me what you did, or what error message you received. So again, if the above formula didn't work, what did you do? Where did you put the formula? What was the exact syntax you used? What was the error message you got?
    Please don't make us work more than we need to. Answer all the questions in your next post. Thanks.

  • How to calculate age in SQL?

    I have a table with DATE as one of the column.
    How do I calculate age?
    Thanks in advance
    -Shilpa

    michaels2 wrote:
    TryWell it still leaves leap year question open. If person was born on February 29, how old is that person on February 28 of a non-leap year? Your code considers it imcomplete year:
    SQL> var dob varchar2(20)
    SQL> exec :dob := '19960229';
    PL/SQL procedure successfully completed.
    SQL> select trunc ( (to_number (to_char (to_date('20090228','yyyymmdd'), 'yyyymmdd'))
      2                  - to_number (to_char(to_date(:dob, 'yyyymmdd'),'yyyymmdd'))
      3                  )
      4                / 10000)
      5            as "Age of Child"
      6    from dual
      7  /
    Age of Child
              12SY.

  • Calculate age in oracle 11g

    how do i calculate age based on date picker in another field on the same table/

    Are you sure of that algorithm?
    orclz> SELECT Round((SYSDATE-to_date('01-JAN-1989','dd-MON-yyyy'))/365) FROM DUAL;
    ROUND((SYSDATE-TO_DATE('01-JAN-1989','DD-MON-YYYY'))/365)
                                                           25
    orclz> SELECT Round((SYSDATE-to_date('01-DEC-1989','dd-MON-yyyy'))/365) FROM DUAL;
    ROUND((SYSDATE-TO_DATE('01-DEC-1989','DD-MON-YYYY'))/365)
                                                           24
    How about this:
    orclz> select extract (year from sysdate) - extract( year from to_date('01-DEC-1989','dd-MON-yyyy')) from dual;
    EXTRACT(YEARFROMSYSDATE)-EXTRACT(YEARFROMTO_DATE('01-DEC-1989','DD-MON-YYYY'))
                                                                                24
    orclz> select extract (year from sysdate) - extract( year from to_date('01-JAN-1989','dd-MON-yyyy')) from dual;
    EXTRACT(YEARFROMSYSDATE)-EXTRACT(YEARFROMTO_DATE('01-JAN-1989','DD-MON-YYYY'))
                                                                                24
    orclz>

  • Calculate Age in an ABAP report

    Hi all you wonderful SAP people,
    I am trying to calculate age in my ABAP report,
    Any function module I can use or code snippet? Your help is much appreciated. Points will be awarded.
    Regards
    Ramorua

    Hi Mohamed,  some characters (plus signs, and spaces around the minus) seem to have gotten lost from your code, maybe during the conversion of the forum. Also, the data type is i, not int.
    Header 1
          DATA: lv_age TYPE i.
          lv_age = sy-datum(4) - lv_birthdate(4).
          IF sy-datum+4(4) LT lv_birthdate+4(4).
            lv_age = lv_age - 1. " or SUBTRACT 1 FROM lv_age.
          ENDIF.

  • Calculate age from a date on numbers

    I am trying to calculate age from a given date in the application numbers. The dates are all in the same column but i need to convert them to ages. I have not been able to find any formulas!
    Thanks

    Hi,
    DATEDIF is a good place to start:
    This example is from the Function help in Numbers, I claim no credit for it.

  • Calculate age in adf

    Gurus,
    Any inbuilt way to calculate age in adf in year, month format ?
    thnks

    Its not perfect, but in the SummitADF application I calculate a time to ship as
    public oracle.jbo.domain.Number calculateTimeToShip(Date ordered,
    Date shipped) {
    if (null != shipped) {
    long days =
    (shipped.getTime() - ordered.getTime()) / (1000 * 60 * 60 *
    24);
    return new Number(days);
    } else
    return new Number(0);
    You can ammend this to work off of the current date.
    Also a quick google shows loads of examples
    e.g.
    http://www.exampledepot.com/egs/java.util/GetAge.html

  • To calculate age

    need to create object to calculate age of an employee when he employed using two columns i.e. date of employment and dob, both columns are in different table.
    how to do that?
    let me know if you need more info
    thanks & regards

    Hi,
    1.In Universe _First create the objects with DOE(Date of employeement), DOB(Date of Birth) as a Date object and right click on those objects and set the Object format as Date/Time YYYY. Click on Add for both objects. and Create one more object and select the Object as
    Sum(@Select(Employee/DOE)-@Select(Employee/DOB))
    2. In Web I_ same like above, 2 objects  creation and apply the Fromat in Universe and Web I create a variable with some name as age and in that
    =Sum(DOE-DOB)
    Click ok.
    Hope it will help you...
    All the Best,
    Madhu....

  • Query to calculate time

    hi all,
    i have 2 udf field of type 'Time', StartTime and EndTime in order to catch the info of some process time.
    again 2 fields of date in order to catch the range of days for the process goes.
    like the following
    Startdate | Enddate | Starttime | Endtime
    15/04/09--| 16/04/09| 9:30- | ---14:00
    Now i need a query to calculate the time differences in hrs. like the process runs thro 4 n half hrs a day and totally as per the table value the total run process time is 9 hrs.
    How to bring out in query any one plz help...
    Thank you so much,

    Hi Yatsea, sorry tis time too its not reteiving correct answer, the values i gave over here is jus for example. but in real there may be many different values. So will be useful in case of providing the query taking in the field names plz.
    i hav a work around working on . will write here, plz guide me to correct the query to get me correct answer.
    in order to find the specific hrs between start and end time for 2 days,
    1. can find first total days within start and end date (EndDate-StartDate) + 1 = 2
    2. 2nd find the hrs between start and end time (EndTime-StartTime) = 4.30 hrs
    3. after tht should multply the 2 values 2 * 4.30 = 8.60 which should round as 9 hrs
    Select (datediff(day,enddate,startdate)+1) * (endtime-starttime)
    will it help..? its not giving correct answer. may gone wrong wit time format. but this concept will give correct anawer i hope...
    PLz...help me getting solution.
    Edited by: New  User on Apr 16, 2009 3:52 PM

  • Can anyone share the query for inventory aging report

    Is there any standard reports for inventory aging in oracle ebs 12.1.3 ....... If not can anyone share the query for inventory aging report

    Hi,
    It may not be so simple as you are trying to reproduce the historical value.  I believe you have to create a temporary table first.  Or you may use Command feather to get the required data in advance.
    Thanks,
    Gordon

Maybe you are looking for