Calculating years between 2 date fields

I am trying to build a form in LiveCycle Designer 7 to report missing persons.  I would like to populate a text field with the number of years between two dates entered in date/time fields; specifically using a missing person's DOB and the date they were last seen to calculate their age when last seen.
Any assistance would be greatly appreciated.
Thanks
Drew

Greetings,
I need an age in months and years.
On my LiveCycyle form I have two date fields 'dob' and 'rdtestdate'.  I am in Australia so we use dd/mm/yyyy as the format.
The field designated to display the calculated result -- 'rdage' -- is set as a calculated-read only text field.
What javascript/formcalc code would I use to calculate the age in years and months, please?
I've been studying and testing the various solutions but don't understand well enough, sorry!  When I paste in a sample and change the field names to match mine, my result remains empty.  Sometimes I get a failed script message as I try to save the form.    I've tried quite a few different scripts to no avail.
Thanks for any assistance.
jeannie

Similar Messages

  • Rip of year from date field

    I have a question. I want to rip of the year from date field. For e.g if date is 01/02/2006 I want just the 01/02 which month and date. I tried to use substr function but it;s giving weird result. I used substr(date, 0,5) but not working. Please suggest.

    If it is a DATE column/variable it is conventional to use TO_CHAR with an appropriate date format, in your case TO_CHAR (date_column, 'MM/YY').

  • Simpler ways of calculating years between

    Hi again,
    I would appreciate numerous versions of calculating years between in years of age
    i think there should be simpler ones than this below:
    SQL> select floor(months_between(hire_date,dob)/12) age from employee;
    AGE
    38
    32
    30
    46
    39
    25
    32
    46
    39
    33
    10 rows selected.
    many thanks
    cube60

    The EXTRACT approach will return wrong age counts for persons having their birthday in this current month, on a given day in this current month but after today.
    Age by minus is also not always accurate.
    E.g:
    SELECT nr
    , birthdate
    , trunc( months_between(sysdate,birthdate) / 12 ) age_by_months_between
    , trunc((SYSDATE - birthdate)/365.25) age_by_minus
    , EXTRACT(YEAR FROM((trunc(SYSDATE)- birthdate)YEAR TO MONTH)) AS age_by_extract
    , floor(months_between(trunc(sysdate),birthdate )/12) age_by_floor
    FROM <table>
    Results:
    BIRTHDATE     AGE_BY_MONTHS_BETWEEN     AGE_BY_MINUS     AGE_BY_EXTRACT     AGE_BY_EXTRACT2
    23-4-1962     45     45     46     45
    25-4-1950     57     57     58     57
    15-4-1990     17     17     18     17
    21-4-1958     49     49     50     49
    20-4-1991     16     16     17     16
    26-4-1981     26     26     27     26
    14-4-1971     36     36     37     36
    15-4-1947     60     60     61     60
    12-4-1955     52     53     53     52
    12-4-1966     41     42     42     41
    12-4-1963     44     45     45     44
    12-4-1974     33     34     34     33
    12-4-1983     24     25     25     24
    12-4-1959     48     49     49     48
    12-4-1942     65     66     66     65
    12-4-1959     48     49     49     48
    12-4-1947     60     61     61     60
    25-4-1932     75     75     76     75
    It seems that months_between is always correct.
    Regards,
    MH

  • Year from date field

    hi
    in cdhdr table udate field is there. i want to retrieve the records belong to 2007
    only. when i am using offset on udate field as udate+0(4) in the select statement it is showing error. plz tell me how to retrieve only year form udate field in select stament.
    regards
    sami

    Hi...
    You can use the LIKE Operator in this Case for checking the conditions.
    Eg
    Select * from CDHDR into table itab where Udate LIKE '2007%'.
    To access the Year field only use...
    SELECT udate(4) FROM cdhdr.....
    <b>reward if Helpful.</b>

  • To filter data acording to year of  date field of a table

    Hi i have a table
    TABLE  T1(ID NUMBER, SET_DATE DATE)I want to select id values from this table by comparing year present in set_date field.
    For that i wrote
    select id from t1 where set_date like '%2010%' ;It's returning no rows.
    But the following code is working
    select id from t1 where set_date like '%10%' ;Though second code is working there is a demerit in both these code because i am not specifying to match year.It's quite possible that 10 may be present any where else, and this query will return all those rows.So how to filter rows according to year?

    You should be careful that applying a function to your date column will bypass any indexes - unless it is an appropriate function based index. It is often better to convert your criteria to a match your data rather than convert your data once for every row in the table. The following example will allow the optimizer to use an index if appropriate;
    with  t1 as(
       select 1 id, sysdate set_date from dual union all
       select 2, add_months(sysdate,-12) from dual)
    select id
    from t1
    where set_date between to_date('01-jan-2010', 'dd-mon-yyyy') and
          to_date('31-dec-2010 23:59:59', 'dd-mon-yyyy hh24:mi:ss');
            ID
             1

  • How to add years to date-field ?

    hi,
    i have a field z_date type d.
    now i have to add 25 years to it, and 35 years, and so on.........
    how to handle this ?
    reg, Martin

    Hi,
    Above posts would not check for leap year dates... so while calculating it might give wrong dates...
    use the FM given below to calculate date with year's...
    data w_date type sy-datum.
    w_date = sy-datum.
    CALL FUNCTION 'J_1H_CAL_DATE_IN_INTERVAL'
      EXPORTING
        date            = w_date
        days            = 0
        months          = 0
       SIGNUM          = '+'
        years           = 30
    IMPORTING
       CALC_DATE       = w_date.
    Regards,
    Siddarth

  • Function Module for calculating hours between dates and their times.

    Hi all,
    Is there any standard function module for calculating the time difference in hours between two dates with start and end times.
    Regards,
    Sudipto.

    Sudipto,
    How're you ????????????????????
    Check out the following Function Module:
    SD_DATETIME_DIFFERENCE (Give the difference in Days and Time for 2 dates)
    Regards,
    Abir
    Don't forget to award Points *

  • Calculating Year to Date Totals

    Develper advises they have no solution in Crystal for the following.  Report requires display of monthly expenditure totals and a YTD total that represents the cummulative total of each month.  The report displays a YTD total for the end of each month.  Problem is that when a given month has a zero value for the monthly expenditure, the report is displaying a zero value for the YTD total and failing to pick up the YTD from the previous month end....
    Does anyone understand the developer's issue and/or have a solution?

    You should be able to group off year, month, put the field in detail section, then create a summary from
    that field.  Right click the field, select insert summary, and select the groups, or footers as needed.
    If that does not work, you may need to try running totals.

  • Performing calculation on text data fields - for Master Data infoobjects

    Gurus,
    I've a MD InfoObject Z_Obj containing set of attributes -  Z_Attr1, Z_Attr2 and Z_Attr3 , the data for this fields contains text ( of single character)
    The requirement goes like this
    Attribute     Value   Value to be displyed in the Report
    Z_Attr1 -      Y                        A
    Z_Attr1 -      N                    <Blank>
    Z_Attr2 -      Y                         B
    Z_Attr3 -      N                     <Blank>
    Z_Attr4 -      Y                        C
    Z_Attr5 -      N                     <Blank>
    Without making use of any ABAP routine , What are the possible ways we can achieve this in Output.
    Remember I want the validation of the fields at report level not at the ODS/DSO/MD InfoObject level.
    Please do help me about the various possibilites.
    Thanks in advance <removed by moderator>
    Regards,
    Yaseen
    Edited by: Siegfried Szameitat on Nov 7, 2008 9:15 AM

    This can be done :
    Create 3 formula variables of type replacement path.
    While creating :
    In the general tab, choose reference characteristic as Z_Obj.
    In Replacement Path tab,
    Replace variable with : Infoobject
    Replace with            : Attribute value
    In below drop down choose your attribute appropriately.
    Now you can use this formula variables to create formula or CKF.
    Hope this helps.

  • Display Years between dates - Need Help.!!!

    Dear Reader,
    I need help to resolve this.
    Below are the values stored in table:
    SOME_ID      START_DATE     END_DATE
    1                     15-NOV-2001        04-MAY-2002
    1                     05-MAY-2004        04-MAY-2007
    1                     05-MAY-2007        27-JAN-2008
    2                     07-NOV-1991        02-FEB-1994
    2                     07-NOV-1998        02-FEB-1999
    For example, the query should return as follows :
    For SOME_ID 1:
    SOME_ID        YEARS
    1                      2001
    1                      2002
    1                      2004
    1                      2005
    1                      2006
    1                      2007
    1                      2008
    Kindly help in providing the solution.
    Thanks in Advance.

    with sample_table as (
                          select 1 some_id,to_date('15-NOV-2001','dd-mon-yyyy') start_date,to_date('04-MAY-2002','dd-mon-yyyy') end_date from dual union all
                          select  1,to_date('05-MAY-2004','dd-mon-yyyy'),to_date('04-MAY-2007','dd-mon-yyyy') from dual union all
                          select 1,to_date('05-MAY-2007','dd-mon-yyyy'),to_date('27-JAN-2008','dd-mon-yyyy') from dual union all
                          select 2,to_date('07-NOV-1991','dd-mon-yyyy'),to_date('02-FEB-1994','dd-mon-yyyy') from dual union all
                          select 2,to_date('07-NOV-1998','dd-mon-yyyy'),to_date('02-FEB-1999','dd-mon-yyyy') from dual
    select  distinct some_id,
                     column_value years
      from  sample_table,
            table(
                  cast(
                       multiset(
                                select  to_number(to_char(start_date,'yyyy')) + level - 1
                                  from  dual
                                  connect by to_number(to_char(start_date,'yyyy')) + level - 1 <= to_number(to_char(end_date,'yyyy'))
                       as sys.OdciNumberList
      where some_id = 1
      order by years
       SOME_ID      YEARS
             1       2001
             1       2002
             1       2004
             1       2005
             1       2006
             1       2007
             1       2008
    7 rows selected.
    SQL> SY.

  • Querying by date field parts: month, year

    Hi,
    is there ability in JDOQL to get month or year of date field and use them in
    filter? Example:
    search(Payment.class, "processDate.ext:getYear() == (select
    c.createDate.ext:getYear() from Client c where clientID == c.ID)");
    thanks,
    Povilas

    is there ability in JDOQL to get month or year of date field and use them in
    filter? Example:
    search(Payment.class, "processDate.ext:getYear() == (select
    c.createDate.ext:getYear() from Client c where clientID == c.ID)");Unfortunately, there is not. As your example indicates, however, you could code
    a custom query extension in Kodo to extract the year from a date in SQL.

  • Working days between two date fields and Changing Factory Calendar

    Hi,
    I have to calculate working days between two date fields excluding the weekends and public holidays for Switzerland.
    I have written the routine using factory calender and its working fine except for two problems now:
    1. If any one of the date field is empty then teh rsult should be zero.
    2. And the below code is working from 1996 but my cleints wants it to work for years before 1996 as well.
    I also tried to change the Start date in SCAL for factory calendar but it says enter values between 1995 to 2020.
    I am new to ABAP. Please help me how i can achieve these for below code.
    DATA: IT_HOLIDAYS type TABLE OF ISCAL_DAY,
          IS_HOLIDAYS TYPE ISCAL_DAY.
    DATA: T_DATE TYPE SY-DATUM,
          P_DATE TYPE SY-DATUM.
    DATA : X_DATE(4) TYPE C.
    DATA: CNT TYPE I.
    REFRESH : IT_HOLIDAYS.
    CLEAR : IT_HOLIDAYS.
    T_DATE = SOURCE_FIELDS-/BIC/ZCCCHP812.
    P_DATE = SOURCE_FIELDS-/BIC/ZCCCHP810.
    CALL FUNCTION 'HOLIDAY_GET'
    EXPORTING
    HOLIDAY_CALENDAR = 'CH'
    FACTORY_CALENDAR = 'CH'
    DATE_FROM = P_DATE
    DATE_TO   = T_DATE
    TABLES
    HOLIDAYS = IT_HOLIDAYS
    EXCEPTIONS
    FACTORY_CALENDAR_NOT_FOUND = 1
    HOLIDAY_CALENDAR_NOT_FOUND = 2
    DATE_HAS_INVALID_FORMAT = 3
    DATE_INCONSISTENCY = 4
    OTHERS = 5.
    DESCRIBE TABLE IT_HOLIDAYS LINES CNT.
    X_DATE = T_DATE - P_DATE - CNT.
    RESULT = X_DATE.
    Please help
    Regards
    Zabina
    Edited by: Syed786 on Nov 2, 2011 9:15 AM

    Hi Zabina,
    Try this function module  'DURATION_DETERMINE'.
    Give the factory calendar and unit as DAY
    With regards,
    Rajesh

  • Are Cube organized materialized view with Year to Date calculated measure eligible for Query Rewrite

    Hi,
    Will appreciate if someone can help me with a question regarding Cube organized MV (OLAP).
    Does cube organized materialized view with calculated measures based on time series  Year to date, inception to date  eg.
    SUM(FCT_POSITION.BASE_REALIZED_PNL) OVER (HIERARCHY DIM_CALENDAR.CALENDAR BETWEEN UNBOUNDED PRECEDING AND CURRENT MEMBER WITHIN ANCESTOR AT DIMENSION LEVEL DIM_CALENDAR."YEAR")
    are eligible for query rewrites or these are considered advanced for query rewrite purposes.
    I was hoping to find an example with YTD window function on physical fact dim tables  with optimizer rewriting it to Cube Org. MV but not much success.
    Thanks in advance

    I dont think this is possible.
    (My own reasoning)
    Part of the reason query rewrite works for base measures only (not calc measures in olap like ytd would be) is due to the fact that the data is staged in olap but its lineage is understandable via the olap cube mappings. That dependency/source identification is lost when we build calculated measures in olap and i think its almost impossible for optimizer to understand the finer points relating to an olap calculation defined via olap calculation (olap dml or olap expression) and also match it with the equivalent calculation using relational sql expression. The difficulty may be because both the olap ytd as well as relational ytd defined via sum() over (partition by ... order by ...) have many non-standard variations of the same calculation/definition. E.g: You can choose to use or choose not to use the option relating to IGNORE NULLs within the sql analytic function. OLAP defn may use NASKIP or NASKIP2.
    I tried to search for query rewrite solutions for Inventory stock based calculations (aggregation along time=last value along time) and see if olap cube with cube aggregation option set to "Last non-na hierarchical value" works as an alternative to relational calculation. My experience has been that its not possible. You can do it relationally or you can do it via olap but your application needs to be aware of each and make the appropriate backend sql/call. In such cases, you cannot make olap (aw/cubes/dimensions) appear magically behind the scenes to fulfill the query execution while appearing to work relationally.
    HTH
    Shankar

  • Date field difference calculation

    Hi all,
    I am new to Adobe and Java scripting so apologies if this has already been answered elsewhere - I have not been able to find it if it has.
    I want to calculate the difference between two dates fields in hours and mins on a form.
    I have two fields, both Date format (dd/mm/yyy HH:MM), a Start and End date and I want the difference between them in the Time format HH:MM.
    Can anyone help me with the script for this? What I have so far is:
    var strStart = this.getField("StartTime").value;
    var strEnd = this.getField("EndTime").value;
    if(strStart.length || strEnd.length)
    var dateStart = util.scand("dd/mm/yyyy HH:MM",strStart);
    var dateEnd = util.scand("dd/mm/yyyy HH:MM",strEnd);
    var diff = dateEnd.getTime() - dateStart.getTime();
    // One Day = (24 hours) x (60 minutes/hour) x
    // (60 seconds/minute) x (1000 milliseconds/second)
    var oneMin = 60 * 60 * 1000;
    var mins = Math.floor(diff/oneMin);
    event.value = util.printd("HH:MM",mins);
    But this is not working...
    Mary

    The result can be formatted using:
    // format result using "h:MM" format
    event.value = util.printf("%,0 0.0f" + ":" + "%,002.0f", nHours, nMinutes);
    One cannot use the date or time formats since the time values will be limited to the hours and minutes values for 1 day, so any time value that is over 23 hours 59 minutes is not possible.
    A full script solution including document level functions for conversion of date strings to minutes and converting minutes to a time string:
    // reusable document level functions;
    function Time2Num(cFormat, cDate) {
    // convert date value with format to number of minutes form Epoch date;
    var oDate = util.scand(cFormat, cDate);
    var nMins =  null;
    if(oDate ==  null) app.alert("Error converting " + cString + " using " + cForamt);
    else nMins = oDate.getTime() / (1000 * 60);
    return Math.floor(nMins);
    } // end Time2Num format
    function Num2Time(cFormat, nMins) {
    // convert number of muniutes to h:MM or HH:MM format;
    // return formatted string for valid formats;
    // return null for invalid formats;
    var cElapsed = null;
    // test for nMins being a number;
    if(isNaN(nMins)) {
    app.alert("Minutes must be number",0, 0);
    } else {
    var nHours = Math.floor(nMins / 60);
    var nMinutes = Math.floor(nMins % 60);
    switch(cFormat) {
    case "h:MM":
    cElapsed = util.printf("%,0 0.0f" + ":" + "%,002.0f", nHours, nMinutes);
    break;
    case "HH:MM":
    cElapsed = util.printf("%,002.0f" + ":" + "%,002.0f", nHours, nMinutes);
    break;
    default:
    app.alert("Invalid format " + cFormat + "\nMust be \"HH:MM\" or \"h:MM", 0, 0);
    break;
    return cElapsed;
    } // end Num2Time function
    // end document level funcitons;
    // custom calculation script;
    event.value = ''; // clear result;
    var strStart = this.getField("StartTime").value;
    var strEnd = this.getField("EndTime").value;
    if(strStart.length || strEnd.length) {
    var nDateStart = Time2Num("dd/mm/yyyy HH:MM",strStart);
    var nDateEnd = Time2Num("dd/mm/yyyy HH:MM",strEnd);
    var nMins = nDateEnd - nDateStart;
    // format result using "h:MM" format
    event.value = Num2Time("h:MM", nMins);
    // end custom calculation script;

  • How to compare table's date field with dropdown year field

    Hi All,
    I have one requirement to display the selected rows from a database table based on the selection of drop down.
    Here, I have one dropdown of year(like 2009,2010,....) and I have one database table which contains one field with "DATE".
    Now, I want to compare table's DATE field with my dropdown field.
    Problem is that table's DATE field is of type "DATS" and dropdown is of type INTEGER(or) STRING ...
    How to compare this fields?
    Can any one please give me solution for this...!
    Thanks in Advance!

    Hi  sreelakshmi.B,
    try the following:
    DATA lt_dats        TYPE TABLE OF dats.
    DATA l_dat_i        TYPE          i.
    DATA l_dat_c_4(4)   TYPE          c.
    DATA l_dat_c_12(12) TYPE          c.
    DATA l_dats_from    TYPE          dats.
    DATA l_dats_to      TYPE          dats.
    *Move Date from Integer to Char
    l_dat_c_4 = l_dat_i = 2005.
    *Create Date From use in WHERE-Clause
    CONCATENATE '01.01.' l_dat_c_4 INTO l_dat_c_12.
    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
         EXPORTING
              date_external            = l_dat_c_12
         IMPORTING
              date_internal            = l_dats_from
         EXCEPTIONS
              date_external_is_invalid = 1
              OTHERS                   = 2.
    IF sy-subrc <> 0.
    ENDIF.
    *Create Date To use in WHERE-Clause
    CONCATENATE '31.12.' l_dat_c_4 INTO l_dat_c_12.
    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
         EXPORTING
              date_external            = l_dat_c_12
         IMPORTING
              date_internal            = l_dats_to
         EXCEPTIONS
              date_external_is_invalid = 1
              OTHERS                   = 2.
    IF sy-subrc <> 0.
    ENDIF.
    * Select records in range
    SELECT *
           FROM [DBTAB]
           INTO TABLE [ITAB]
           WHERE [DATE] BETWEEN l_dats_from
                        AND     l_dats_to.
    Regards
    REA

Maybe you are looking for