How to get days , months , years between two dates with groovy

I've a table that contains Start Date and End Date and I want to get the difference between then in this format 2 days , 1 moth , 1year
Can I make this with Groovy
I've added a transient attribute to a view object and make its value      return (EndDate) - (StartDate); but this returns the difference of days like 200 day
I want it in this format 2 days , 1 moth , 1year

AFAIK - You cannot do it in groovy.
You can achieve the same using the transient variable approach.
Create a VORowImpl Class for VO, and in the getter method of the transient variable - do the necessary logic and return the string as required in your use-case.
Thanks,
Navaneeth

Similar Messages

  • I need FM calc. days/months/years between 2 dates but computes the work day

    I need FM calc. days/months/years between 2 dates but computes the work day.
    someone knows ?

    Hi,
    The FM is 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
    Check the following example:
    DATA: EDAYS   LIKE VTBBEWE-ATAGE,
          EMONTHS LIKE VTBBEWE-ATAGE,
          EYEARS  LIKE VTBBEWE-ATAGE.
    PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,
                TODATE   LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.
    call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
      exporting
        i_date_from          = FROMDATE
        i_date_to            = TODATE
      I_FLG_SEPARATE       = ' '
      IMPORTING
        E_DAYS               = EDAYS
        E_MONTHS             = EMONTHS
        E_YEARS              = EYEARS.
    WRITE:/ 'Difference in Days   ', EDAYS.
    WRITE:/ 'Difference in Months ', EMONTHS.
    WRITE:/ 'Difference in Years  ', EYEARS.
    INITIALIZATION.
    FROMDATE = SY-DATUM - 60.
    Regards,
    Bhaskar

  • How to calculate the month difference between two date char. in Query?

    Customers would like to see how many months passed between two date type of characteristics (e.g., the month difference between the current date and the scheduled delivery date in the record) and put the result into the column as KF. 
    We would have to grab the fiscal year/period kind of value and then do the subtraction, e.g., if the current date value is 2/28/2008 and the scheduled delivery date value in the record is 12/01/2007, the correct result should be 2 month difference between these two date values, but could someone here give us the technical light on how to make this happen in query design?
    Thanks and we will give you reward points for the correct anwsers!

    Hi Kevin,
    The Badi is RSR_OLAP_BADI.
    You can create an implementation using Transaction  SE18.
    The implementation is per cube and is defined in the filters.
    In the Implementation you have the following methods :
    1. Define : Here you will provide the Keyfigure you need as a virtual one.
    2. Initilialize : Any Init Function you want to do.
    3. Compute. This is called per datarecord and here you can cimpute your value.
    Hope this helps.
    Pralay Ahluwalia

  • How to calculate the hour difference between two dates?

    hi all,
    how to calculate the hour difference between two dates?
    eg i trying this...
    ((TO_DATE(TO_CHAR(GRNi.reference_date_4,'hh24:mi'),'hh24:mi') -
    TO_DATE(TO_CHAR(NVL(GRNi.reference_date_3,SYSDATE),'hh24:mi'),'hh24:mi'))*24)*60 Act_Hr
    Reg.
    AAK

    Hi
    To break the diff between 2 dates into days, hours, minutes, sec -- you can use the following:
    select to_char( created, 'dd-mon-yyyy hh24:mi:ss' ),
    trunc( sysdate-created ) "Dy",
    trunc( mod( (sysdate-created)*24, 24 ) ) "Hr",
    trunc( mod( (sysdate-created)*24*60, 60 ) ) "Mi",
    trunc( mod( (sysdate-created)*24*60*60, 60 ) ) "Sec",
    to_char( sysdate, 'dd-mon-yyyy hh24:mi:ss' ),
    sysdate-created "Tdy",
    (sysdate-created)*24 "Thr",
    (sysdate-created)*24*60 "Tmi",
    (sysdate-created)*24*60*60 "Tsec"
    from all_users
    where rownum < 50
    HTH
    RangaReddy

  • How to count number of sundays between two dates

    Hi
    I want number of Sundays between two dates
    example
    number of Sundays count between '01-04-2013' and '30-04-2013' in one select query I have to include this as sub query in my select statement.

    Hi,
    ChakravarthyDBA wrote:
    Hi
    I want number of Sundays between two dates
    example
    number of Sundays count between '01-04-2013' and '30-04-2013' in one select query I have to include this as sub query in my select statement.Here's one way:
    SELECT       early_date
    ,       late_date
    ,       ( TRUNC (late_date + 1, 'IW')
           - TRUNC (early_date,        'IW')
           ) / 7       AS sundays
    FROM       table_x
    ;This does not depend on your NLS settings.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
    Point out where the statment above is getting the wrong results, and explain, using specific examples, how you get the right results from the given data in those places.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • Get number of hours between two dates and two hours using factory calendar

    Hello all,
    I have the following requirement: I need to calculate the number of hours between two dates and two hours (start date- finish date and start hour-finish hour) or timestamps using a factory calendar. I must program it on CRM environment.
    Does anybody know a function module that makes it?
    Thanks in advance.
    Carmen

    Please check function module DURATION_DETERMINE.
    - April King

  • How to get  day if we give the date

    i want the day for tghis date(16-march-2006), how to get that
    select to_char(sysdate,'day') from dual,it gives the correct day but select to_char('16-mar-06','day') from dual it gives error,
    so how to get that day

    Hi
    First convert it '16-MAR-06' to date then give format
    select to_char(to_date('16-MAR-06','DD-MON-YY'),'day') from dual;
    TO_CHAR(T
    thursday
    Khuram Siddiqui
    [email protected]

  • How to get the month value in a date?

    I am retrieving a Date from the database using the getDate() method! However, I want the value of the month in this obtained result, which i want to compare with an integer!
    I dont see any other option but to use the deprecated getMonth() method on this Date object! Or rather get the date as a String & apply the substring methods to get the reqd value!
    Is there any other go on this?

    Hi
    You can use GregorianCalendar.
    Date d = new Date();
    Calendar c = new GregorianCalendar();
    c.setTime(d);
    System.out.println(c.get(Calendar.MONTH)+1);
    -nmw-

  • How to Calculate Sum of Difference between two dates

    Hi,
    I'm using BI Publisher in Siebel CRM.
    In RTF template I have the following expression to calculate the Difference between dates
    <?xdoxslt:date_diff( 'd' , psfn:totext(CIRGSubmittedDate,"yyyy-MM-dd","MM/dd/yyyy"), psfn:totext(Done,"yyyy-MM-dd","MM/dd/yyyy"), $_XDOLOCALE, $_XDOTIMEZONE)?>
    The above expression works for me to calculate the dates.
    I need to calculate the Sum of all these dates for a Group.
    Want to know the Syntax for Sum function using Date_diff.
    Tried the following and didn't work.
    <?Sum(xdoxslt:date_diff( 'd' , psfn:totext(CIRGSubmittedDate,"yyyy-MM-dd","MM/dd/yyyy"), psfn:totext(Done,"yyyy-aMM-dd","MM/dd/yyyy"), $_XDOLOCALE, $_XDOTIMEZONE))?>
    Not sure what I'm doing wrong here...
    Anyone please help...
    Thanks
    PV

    Hi
    To break the diff between 2 dates into days, hours, minutes, sec -- you can use the following:
    select to_char( created, 'dd-mon-yyyy hh24:mi:ss' ),
    trunc( sysdate-created ) "Dy",
    trunc( mod( (sysdate-created)*24, 24 ) ) "Hr",
    trunc( mod( (sysdate-created)*24*60, 60 ) ) "Mi",
    trunc( mod( (sysdate-created)*24*60*60, 60 ) ) "Sec",
    to_char( sysdate, 'dd-mon-yyyy hh24:mi:ss' ),
    sysdate-created "Tdy",
    (sysdate-created)*24 "Thr",
    (sysdate-created)*24*60 "Tmi",
    (sysdate-created)*24*60*60 "Tsec"
    from all_users
    where rownum < 50
    HTH
    RangaReddy

  • Calculated columns to get difference between two dates with half day

    Hi,
    So there is the problem I'm using a calculated column to track the number of day when an employee make a vacation request. I'm already taking weekends of the case but now I would need to be able to ask for only a half day off.
    How could I perform that without taking out my first requirement?
    Just in case there is my current formula:
    =IF(AND((WEEKDAY([EndDate],2))<(WEEKDAY([StartDate],2)),((WEEKDAY([StartDate],2))-(WEEKDAY([EndDate],2)))>1),(((DATEDIF([StartDate],[EndDate],"D")+1))-(FLOOR((DATEDIF([StartDate],[EndDate],"D")+1)/7,1)*2)-2),
    Thanks for your answers :)  

    Hi amber,
    you can simple calculate.
    try this:
    DATA: date1 like sy-datum,
          date2 like sy-datum.
    data  I type i.
    date1 = '20070301'.
    date2 = '20070228'.
    i = date1 - date2.
    write: / date1, date2, i.
    date1 = sy-datum.
    date2 = sy-datum - 30.
    i = date1 - date2.
    write: / date1, date2, i.
    Regards, Dieter

  • How to make a perfect validations between two dates..?

    Hello,
    i want to check this code with u christian pls,
    DECLARE
    V_MESSAGE NUMBER(2);
    V_TO_DATE DATE ;
    V_FROM_DATE DATE;
    CURSOR MATERIALS IS
                   SELECT MATERIAL_CODE,TO_DATE,FROM_DATE
                   FROM PLN_TANK_MATERIALS
                   WHERE TANK_CODE= :PLN_TANK_MATERIALS.TANK_CODE;
    BEGIN
         FOR I IN MATERIALS
         LOOP
              IF (:FROM_DATE > I.FROM_DATE ) AND (:TO_DATE < I.TO_DATE ) THEN          
                   V_MESSAGE := FUNC_MSG(1,'CASE 1');      
              RAISE FORM_TRIGGER_FAILURE;          
              ELSIF (:FROM_DATE > I.FROM_DATE ) AND (:TO_DATE > I.TO_DATE ) THEN     
                   V_MESSAGE := FUNC_MSG(1,'CASE2');
              RAISE FORM_TRIGGER_FAILURE;
              ELSIF (:FROM_DATE < I.FROM_DATE ) AND (:TO_DATE > I.FROM_DATE ) THEN     
                   V_MESSAGE := FUNC_MSG(1,'CASE3');
              RAISE FORM_TRIGGER_FAILURE;     
              ELSIF (:FROM_DATE < I.FROM_DATE ) AND (:TO_DATE > I.TO_DATE ) THEN     
                   V_MESSAGE := FUNC_MSG(1,'CASE4');
                             RAISE FORM_TRIGGER_FAILURE;     
              ELSIF (:FROM_DATE = I.FROM_DATE)OR (:TO_DATE = I.TO_DATE )
                        OR (:FROM_DATE = I.TO_DATE)OR (:TO_DATE = I.FROM_DATE ) THEN     
                        V_MESSAGE := FUNC_MSG(1,'CASE5');
                   RAISE FORM_TRIGGER_FAILURE;
              END IF;          
         END LOOP;          
    END;
    =========================================================
    Regards ,
    Abdetu..

    i want to check this code with u christian plsnote that I am more Database PL/SQL Developer than Forms Developer...
    also note that I am earning 20 Bucks/Code Review :D
    But it would be nice to tell me your problem with the upper source, than maybe I can help u...
    best regards
    Christian

  • Java code to get the difference between two dates in days

    Hi ppl,
    I need to write a user defined function to get the difference between two date nodes, in days.Please help me out
    regards,
    Prashanth

    Hi,
    have a look at those two:
    (How do I calculate the difference between two dates?)
    http://joda-time.sourceforge.net/faq.html
    Calculating the Difference Between Two Datetime Stamps
    http://www.xmission.com/~goodhill/dates/deltaDates.html
    Get difference in days
    http://javaalmanac.com/egs/java.util/CompDates.html
    Regards,
    michal

  • Studio : Chart Based on day/month/year

    In Studio , There is a requirement for us to display chart based on day/month/year .
    Since Date attribute is not displayed as a Dimension in the chart configuration list , I have divided  date attribute into  day/month/year attributes and based on that I generated a sample chart
    But now I'm facing with a problem
    Suppose there are records for only July and Sep then the chart shows up for July and Sep , It doesn't show up for august.
    I agree that there are no records for august in my data domain that is the reason august is not displayed in the chart . But as per our requirement we should display august as well with zero count.
    I'm curious to know if there is any way to do this .

    The idea behind the calendar record type is it is a secondary, new record type you're introducing that compliments your "sales" record type.  The RECORDs you provided would be your "sales" record type, not your "calendar" record type.  To continue with your example, your "sales" records would look like what you provided:
    =============== RECORD ==================
    Id: 1
    sales_amount : 1000
    Month: Oct
    RecordType: sales
    date: 2012-10-01T00:00:00.000Z
    day: 01
    year: 2012
    =============== RECORD ==================
    Id: 5
    sales_amount: 1000
    Month: Dec
    RecordType: sales
    date: 2012-12-01T00:00:00.000Z
    day: 01
    year: 2012
    ==========================================
    And your "calendar" record type would be loaded subsequently.  I usually provide one Endeca record for every day for this record type:
    =============== RECORD ==================
    Id: 1
    Month: Oct
    RecordType: calendar
    date: 2012-10-01T00:00:00.000Z
    day: 01
    year: 2012
    =============== RECORD ==================
    Id: 2
    Month: Oct
    RecordType: calendar
    date: 2012-10-02T00:00:00.000Z
    day: 02
    year: 2012
    ==========================================
    (and so on, one for each day up to today...yawn)....
    =============== RECORD ==================
    Id: 790
    Month: July
    RecordType: calendar
    date: 2013-07-31T00:00:00.000Z
    day: 31
    year: 2013
    ==========================================
    Thus, when you write an EQL statement like:
    RETURN foo AS SELECT
    SUM(sales_amount) AS "TotSales"
    GROUP BY Month
    You will get a Month bucket for every month, where the "calendar" record type will be sure to offer a month where sales don't offer it...aka. fill in any "holes".
    HTH,
    Dan
    http://branchbird.com

  • Using pl/sql function for each day between two dates.

    Hi,
    create TABLE EMP(
    ID_EMP NUMBER,
    DT_FROM DATE,
    DT_TO DATE,
    CREATE_DATE DATE);
    into EMP(ID_EMP, DT_FROM, DT_TO, CREATE_DATE)
    Values(100, TO_DATE('07/01/2008 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('04/30/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),TO_DATE('05/08/2009 14:11:21', 'MM/DD/YYYY HH24:MI:SS'));
    I have a function called  elig_pay_dates(date p_date), which returns the code for  person payment eligibility for a particular date. For paid dates it's 'P' and for unpaid dates it's 'N'.
    How can I check this function between two dates for each day. Example : 07/01/2008 to 04/30/2010.
    By using this function with select I needs to display the dates when there is a change in status.
    I am expecting data in following manner from above logic(this is example):
    07/01/2008 --- 07/01/2009 ---'P'
    07/02/2009 -- 07/25/2009 ----'N'
    07/26/2009 -- 01/01/2010 ---'P'
    01/02/2010 -- 01/13/2010 --'N'
    01/14/2010 -- 01/18/2010 --'P'
    01/19/2010 -- 04/30/2010 -- 'N'
    I thought of looping for each day date but that seems to be expensive for online application. Is there any way that I can achieve this requirement with sql query ?
    Thanks for your help,

    Certainly not the best way to code the requirement, but it does achieve the result you are looking for in a fairly quick time
    create or replace
    function test_ret_paid_unpaid (p_date in date)
    return varchar2
    is
      v_ret     varchar2(1);
    begin
      if ( (p_date between to_date('07/02/2009', 'MM/DD/YYYY') and to_date('07/25/2009', 'MM/DD/YYYY') ) or
           (p_date between to_date('01/02/2010', 'MM/DD/YYYY') and to_date('01/13/2010', 'MM/DD/YYYY') ) or
           (p_date between to_date('01/19/2010', 'MM/DD/YYYY') and to_date('04/30/2010', 'MM/DD/YYYY') )
        then v_ret := 'N';
      else
        v_ret := 'Y';
      end if;
      return v_ret;
    end;
    Wrote file afiedt.buf
      1  with get_paid_unpaid as
      2  (
      3    select dt_from start_date, dt_to end_date, dt_from + level - 1 curr_date, test_ret_paid_unpaid(dt_from + level - 1) paid_unpaid,
      4           row_number() over (order by dt_from + level - 1) rn_start,
      5           row_number() over (order by dt_from + level - 1 desc) rn_end
      6      from test_emp
      7    connect by level <= dt_to - dt_from + 1
      8  ),
      9  get_stop_date as
    10  (
    11  select start_date init_date, end_date, curr_date, paid_unpaid,
    12         case when paid_unpaid != lag(paid_unpaid) over (order by curr_date) or rn_start = 1 or rn_end = 1
    13          then curr_date
    14          else null
    15         end start_date,
    16         case when paid_unpaid != lead(paid_unpaid) over (order by curr_date) or rn_start = 1 or rn_end = 1
    17          then curr_date
    18          else null
    19         end stop_date
    20    from get_paid_unpaid
    21  )
    22  select period, paid_unpaid
    23    from (
    24  select init_date, curr_date, start_date, end_date, stop_date,
    25         case when paid_unpaid = lead(paid_unpaid) over (order by curr_date)
    26                then nvl(start_date, init_date) || ' - ' || lead(stop_date, 1, end_date) over (order by curr_date)
    27              else null
    28         end period,
    29         paid_unpaid
    30    from get_stop_date
    31   where stop_date is not null or start_date is not null
    32         )
    33*  where period is not null
    12:06:10 SQL> /
    PERIOD                                             PAID_UNPAID
    01-JUL-08 - 01-JUL-09                              Y
    02-JUL-09 - 25-JUL-09                              N
    26-JUL-09 - 01-JAN-10                              Y
    02-JAN-10 - 13-JAN-10                              N
    14-JAN-10 - 18-JAN-10                              Y
    19-JAN-10 - 30-APR-10                              N
    6 rows selected.
    Elapsed: 00:00:00.35

  • 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

Maybe you are looking for