PLD - How to calculate difference in days

Hi,
I have a print layout with two different dates (posting date and current date). I need to show the difference between these dates in days. Apparently a formula field with one field minus the other field doesn't do it .
How can I get the number of days between two dates ?
Any help is appreciated.
Regards,
Johan

Hi Johan..
Have you checked with the following thread..
http://scn.sap.com/thread/1074105
Hope Helpful
Regards
Kennedy

Similar Messages

  • Calculate Difference in Days Between two Dates

    Hi,
    I'm trying to figure out how to calculate the difference in days between two dates using JavaScript in LiveCycle. (JavaScript knowledge = minimal)
    Where "Start_Date" and "Current_Date" are the names of the two dates in the Hierarchy palette. (both Date/Time Field)
    *Current date is using the Object > Value > Runtime Property > Current Date/Time
    I need a Text or Numeric field displaying the difference in days. (Difference_in_Days)
    I've noticed the following code being pretty standard amongst other responses:
    var 
    Start_Date = new Date(Start_Date);
    var 
    Current_Date = new Date(Current_Date);
    var 
    nAgeMilliseconds = Current_Date.getTime() - Start_Date.getTime();
    var 
    nMilliSecondsPerYear = 365 * 24 * 60 * 60 * 1000;
    I know there's code missing, and the above code might not be correct.
    Please advise.

    Where "DateField01" = user entered date field
    Where "DateFiled02" = Current Date/Time (Runtime Property)
    where "Subform" = the subform containing DateField01
    My script now resembles:
    var oneDay = 24*60*60*1000;
    var firstDate = new Date(Subform.DateField01.rawValue);
    var secondDate = new Date(DateField02.rawValue);  
    (firstDate.getTime() - secondDate.getTime()) / oneDay;
    I tried adding:
    app.alert(String(diffDays));
    Although I assume the reason I didn't get an error is because DateField01 is empty when the form is opened.
    If I swap in actual dates instead of fields it works perfectly.
    When I use the fields I have no information populating after I enter a date in "DateField01"

  • How to calculate number of days in ABAP?

    Hi,
    I have a condition as below:
    If (field1 - field2) > 12 Months
    E.g field1 = 31.05.2011 & field2 = 10.11.2011
    Can SAP actually minus dates and check if the difference is greater than 12 months?
    How do I perform this calculation?
    Pls advice.
    Thanks!
    Moderator message : Date FAQ, duplicate post.  Thread locked.
    Edited by: Vinod Kumar on Mar 2, 2012 1:50 PM

    Hi,
    If your calculating dates please do not manually calculate it like that.
    You need to determine like week numbers, month and days.
    The best way to do it is by using FM related to dates. Play around with these FMs in your program:
    Function Modules related to Date and Time Calculations
    CALCULATE_DATE  - Calculates the future date based on the input .
    DATE_TO_DAY - Returns the Day for the entered date. 
    DATE_COMPUTE_DAY - Returns weekday for a date
    DATE_GET_WEEK - Returns week for a date
    RP_CALC_DATE_IN_INTERVAL - Add days / months to a date
    DAY_ATTRIBUTES_GET - Returns attributes for a range of dates specified
    MONTHS_BETWEEN_TWO_DATES - To get the number of months between the two dates.
    END_OF_MONTH_DETERMINE_2 - Determines the End of a Month.
    HR_HK_DIFF_BT_2_DATES -Find the difference between two dates in years, months and days.
    FIMA_DAYS_AND_MONTHS_AND_YEARS - Find the difference between two dates in years, months and days.
    WEEK_GET_FIRST_DAY - Get the first day of the week
    SD_CALC_DURATION_FROM_DATETIME - Find the difference between two date/time and report the difference in hours
    L_MC_TIME_DIFFERENCE - Find the time difference between two date/time
    HR_99S_INTERVAL_BETWEEN_DATES - Difference between two dates in days, weeks, months
    LAST_DAY_OF_MONTHS - Returns the last day of the month
    DATE_CHECK_PLAUSIBILITY - Check for the invalid date.
    DATE_2D_TO_4D_CONVERSION - Year entry: 2-character to  4-character.
    DAY_IN_WEEK  - Input date and will give the name of the day 1-monday,2-Tuesday....
    SD_DATETIME_DIFFERENCE - Give the difference in Days and Time for 2 dates

  • How to calculate difference and percentage in matrix report dynamic columns in SSRS 2008

    Hi Friends,
    I need to calculate Difference and Percentage In matrix report SSRS 2008
    1) Row grouping based On Product
    2) Column Grouping Week and Fiscal Year Current week  and Previous Year same Weeks 
    3)Data Invnetory(Value fileld)
    Example:
    If value1 and Value2 Available we need to calculate Percentage and Difference.Otherwise Not required NA I need to Show.
    For example If Particular week,Current year data is available,Previous year  week data is not available No
    need to cal Diff and Percentage we need to show Empty.
    Below Code is working for If two values is available.
    If any one of the fiscal year week data is not there it's taking some garbage values.
    I tries with If condition in GetPCT() and GetDiff() It's not working.
    Can some one please help me on this.
    I am using the custom code 
    Public Shared Value1 as String
    Public Shared Value2 as String
    Public Shared previous as string
    Public Shared previousweek as string
    Public Shared Function GetValue(Value as String,partner as String,Week as String) as String
    If partner =previous and Week =previousweek Then
    Value2=Value
    Else
    previous=partner
    previousweek=Week
    Value1=Value
    End If
    return Value
    End Function
    Public Shared Function GetDiff()
    return Value2-Value1
    End Function
    Public Shared Function GetPct()
    return (Value2-Value1)/Value1
    End Function
    How to handle this.
    Thank You, Manasa.V

    Hi veerapaneni,
    According to your description, if one of the fiscal year week doesn’t have data, the custom code returns false results.
    For your requirement, if NULL value exists in the database, we should replace it as zero then perform calculate. So within the code, we should judge whether the value is NULL. To achieve your goal, please refer to the steps below:
    1. Create a table like below.
    create table dif4
    ([Product Group] varchar(50),
    [Week] varchar(50),
    [Fiscalyearweek] varchar(50),
    value int
    insert into dif4 values
    ('Desktops','W01','FY14W01',0),
    ('Desktops','W01','FY15W01',45),
    ('Desktops','W02','FY14W02',null),
    ('Desktops','W02','FY15W02',30),
    ('Desktops','W03','FY14W03',12),
    ('Desktops','W03','FY15W03',50),
    ('Notebooks','W01','FY14W01',35),
    ('Notebooks','W01','FY15W01',56),
    ('Notebooks','W02','FY14W02',45),
    ('Notebooks','W02','FY15W02',87),
    ('Notebooks','W03','FY14W03',75),
    ('Notebooks','W03','FY15W03',105),
    ('Tablets','W01','FY14W01',34),
    ('Tablets','W01','FY15W01',46),
    ('Tablets','W02','FY14W02',49),
    ('Tablets','W02','FY15W02',96),
    ('Tablets','W03','FY14W03',42),
    ('Tablets','W03','FY15W03',113)
    2. Add the custom code in the Report Properties.
    Public Shared Value1 as Integer
    Public Shared Value2 as Integer
    Public Shared previous as string
    Public Shared previousweek as string
    Public Shared Function GetValue(Value as Integer,product as String,Week as String) as Integer
    If Value=Nothing Then
    Value=0
    End If
    If product =previous and Week =previousweek Then
    Value2=Value
    Else
    previous=product
    previousweek=Week
    Value1=Value
    End If
    return Value
    End Function
    Public Shared Function GetPct()
    If Value1=0 Then
    return 0
    Else
    return (Value2-Value1)/Value1
    End If
    End Function
    Public Shared Function GetDiff()
    return Value2-Value1
    End Function
    3. Design the matrix like below.
    4. Then get the expected results.<o:p></o:p>
    If you have any question, please feel free to ask.
    Best regards,
    Qiuyun Yu
    Qiuyun Yu
    TechNet Community Support

  • How to calculate number of days in hijri

    Dear all,
    I need to develop a custom report in which i required to calculate number of days in hijri month and also the first and last day of the hijri month. we normally use Last_date(sysdate) function to get the last date of the english calender. but how can we find same for month.
    Looking after for your support.
    Regards,
    Saquib

    Convert to hirjih date using:
    select
    to_char(sysdate,'YYYY/MM/DD','NLS_CALENDAR=''English Hijrah''') hijrih_date
    from dual;
    You can replace sysdate with the date of your choice.
    Also I wrote this for my last project:
    /* get hirjih date */
    FUNCTION get_hijrah_date(
    p_date in date,
    p_date_format in varchar2
    ) return varchar2
    is
    v_hijrah_date varchar2(500);
    begin
    select
    to_char(p_date,p_date_format,'NLS_CALENDAR=''English Hijrah''')
    into v_hijrah_date
    from dual;
    return v_hijrah_date;
    end get_hijrah_date;
    So you can have get_hijrah_date(sysdate,'DD-MON-YYYY') from dual;
    (or any other date formate of your choice)
    Edited by: igwe on Jan 30, 2013 8:07 AM

  • How to calculate no of day in a month

    Hi All,
    I am have one cube in that i am getting only fiscalyear/period and variant.
    now my question is how calculate no of day in my fiscalyear/period (ex : 007.2010) this month of oct .is is possible in update rules.
    or it can be possible in report level
    for this i required ABAP logic any one help on this.
    Reagrds
    Anil

    In update rule / transformation write routine, in routine use function module /OSP/GET_DAYS_IN_MONTH. pass  period/month as input to routine/FM & output of this function module get into one variable & pass that variable to result.
    CALL FUNCTION '/OSP/GET_DAYS_IN_MONTH'
      EXPORTING
        iv_date       = SOURCE_FIELDS-fiscper
    IMPORTING
       EV_DAYS       = days
    Result =  days
    Days is a variable declare locally in routine
    Edited by: Swapnil Dharia on Jan 14, 2010 2:36 PM

  • How to calculate difference between date in hours?

    Hi All.
    I need calculate difference between first and last date. I'm using the code below:
    int differenceDate = CalendarRule.elapsedDays(fromDate : myFirstDate, toDate : myLastDate);
    This code return an result in days. But I need that result was in hours.
    Has anybody help me?

    Interval dif;
    dif = myLastDate - myfirstDate;
    display((dif.hours));
    Hope it helps

  • How to get difference in days between 2 dates excluding weekends

    Hi all,
    i have a requirement, to calculate the difference between 2 dates, in days.
    eg: 01/08/2007 and 05/08/2007.
         Difference = 4 days.
    But here my actual requirement is i have to calculate this difference excluding weekends (saturday n sundays).
    eg: 01/08/2007 -
    Thursday
         05/08/2007 -
    Monday
    so now Difference = 2 days.
    Please help me regarding this.
    Points will be rewarded for helpfull answers.
    Thanks in Advance.
    Regards,
    Vineel

    see these codes of rich
    report zrich_0003.
    data: begin of itab occurs 0,
          datum type sy-datum,
          end of itab.
    data: weekday like dtresr-weekday.
    data: number_lines type i.
    parameters: p_sdatum type sy-datum,
                p_edatum type sy-datum.
    itab-datum = p_sdatum.
    append itab.
    do.
      if itab-datum = p_edatum.
        exit.
      endif.
      itab-datum = itab-datum + 1.
      call function 'DATE_TO_DAY'
           exporting
                date    = itab-datum
           importing
                weekday = weekday.
      if weekday = 'Sat.'
        or weekday = 'Sunday'.
        continue.
      endif.
      append itab.
    enddo.
    describe table itab lines number_lines.
    write:/ 'Number of days between dates is', number_lines.
    and
    report zrich_0001.
    parameters: p_start type sy-datum,
                p_end   type sy-datum.
    data: idays type table of   rke_dat with header line.
    data: workingdays type i.
    call function 'RKE_SELECT_FACTDAYS_FOR_PERIOD'
         exporting
              i_datab               = p_start
              i_datbi               = p_end
              i_factid              = 'P8'  " Fact Calender ID
         tables
              eth_dats              = idays
         exceptions
              date_conversion_error = 1
              others                = 2.
    describe table idays lines workingdays.
    write:/ workingdays.
    I want to find the No.of working days between the two dates
    regards,
    srinivas

  • How to calculate Date and Days

    Hi BW Experts,
    I have requirement, I have field original GI Date and  it is calculating based on 'Original promise date'-'Transport time'. Formula is 'Original GI Date' = 'Original promise date'-'Transport time'.
    We are getting data for original promise date as Date format and  Transport time as Days (ex: 1 or 2 days).
    Here, how can I convert into Date or how can I calculate Date and Days. I am working on BW3.5 .
    Please help me how can I overcome this requirement.
    Points will be assign.
    regards
    Yedu.

    Hi Ventatesh
    It's not a problem
    You can subtract days from date to get the resultant date
    Original Promise time  =  GI Date  - Transit time ( in days)
    Add Original Promise Time in your data target and fill that up with the above rule.
    If the above is not working you can use this function module
    DATE_IN_FUTURE
    Here you need to pass Date and Days to get future date. Only trick you need to apply that if the transit days is 5 days, you pass -5 to this function module.
    But this function module is not available in BW system. Just copy the code from ECC system and create a Z FM for BW system
    Regards
    Anindya
    Edited by: Anindya Bose on Feb 9, 2012 4:36 AM

  • How to calculate no of days in an year

    Hi,
    can some one provide a simple way to calculate no of days in a year if we know processing date.
    thanks
    CDPrasad

    select
       trunc(input_date, 'YYYY')  as the_year,
       add_months(trunc(input_date, 'YYYY'), 12)
       trunc(input_date, 'YYYY')  as days_in_year  
    from
       select
          add_months(sysdate, -12 * level) as input_date
       from dual
       connect by level <= 20
    12  );
    THE_YEAR          DAYS_IN_YEAR
    01-JAN-2009 12 00:00           365
    01-JAN-2008 12 00:00           366
    01-JAN-2007 12 00:00           365
    01-JAN-2006 12 00:00           365
    01-JAN-2005 12 00:00           365
    01-JAN-2004 12 00:00           366
    01-JAN-2003 12 00:00           365
    01-JAN-2002 12 00:00           365
    01-JAN-2001 12 00:00           365
    01-JAN-2000 12 00:00           366
    01-JAN-1999 12 00:00           365
    01-JAN-1998 12 00:00           365
    01-JAN-1997 12 00:00           365
    01-JAN-1996 12 00:00           366
    01-JAN-1995 12 00:00           365
    01-JAN-1994 12 00:00           365
    01-JAN-1993 12 00:00           365
    01-JAN-1992 12 00:00           366
    01-JAN-1991 12 00:00           365
    01-JAN-1990 12 00:00           365
    20 rows selected.
    TUBBY_TUBBZ?The above shows the number of days in a year for the past 20 years.
    So assuming you had a variable .. called "input_date"
       trunc(input_date, 'YYYY')  as the_year,
       add_months(trunc(input_date, 'YYYY'), 12)
       trunc(input_date, 'YYYY')  as days_in_year   Would do it.

  • How to calculate number of days excluding weekends

    I have the following <u>key figures</u> in my InfoCube:
    Date Released to Vendors key figure - ZRELDT
    Date Awarded to a Vendor key figure - ZAWRDT
    In my BEx query, I need to calculate the difference between these two key figures but the weekends should be excluded.  For example, if the value of ZRELDT is 08/10/2007 (which is a Friday) and the value of ZAWRDT is 08/13/2007, the result should just be 1 day and not 3 days since the other days pertain to a Saturday and a Sunday.
    How do I address this in the formula when creating the Query?
    thanks.

    Hi,
    Use func module HOLIDAY_GET need to pass the Holiday Cal the company use
    and also 
    FM: DATE_CONVERT_TO_FACTORYDATE.
    One way to use this:
    Assuming:
    - You have the start & end dates in variables.
    - Keep a few counters
    Logic:
    - Pass start date to DATE_CONVERT_TO_FACTORY_DATE with the parameter +
    - If this date is not a factory date, the next date which is a factory day is returned. (I.e. passed Sunday as param, got a Monday date returned). If the day passed to the function is the same as the date returned, this is a factory day (working day)
    - If the date passed to the function is not the same as the returned day then this day was not a factory day, meaning not a work date. Add 1 to a counter
    - Pass the first day + 1 (use another counter for + N)
    - Stop loop when passed parameter is equal to stop date.
    You can replicate the factory calendar from R/3, CRM etc in your source system in RSA1 (transfer globals). In your function call, you specify which factory calendar to use
    hope this help

  • Calculate difference of days between two dates

    Hi,
    Date1: It is a mandatory type-in date at the time of query execution. How to create it? By default, it should take today's calendar date.
    Date2: it is a date in a Char format. (0NETDUEDATE) in one of the dimension of InfoCube.
    In query column
    of days = Date1 - Date2.
    I would prefer to use in global variable.
    Please help.
    ~S

    Hello ,
               For date 1 create a characteristic variable(ready to input) on 0calday with customer exit as processing type and key in the following code to get the system date.
    data aktdat  like sy-datum.
    when 'test'.
        aktdat = sy-datum(6).
        clear l_s_range.
        l_s_range-low   =  aktdat.
        l_s_range-sign = 'I'.
        l_s_range-opt = 'EQ'.
        append l_s_range to e_t_range.
    Then create a user entry variable for date 2 using the characteristic mentioned,
    then for calculating the days difference check the following.
    http://www.sd-solutions.com/documents/SDS_BW_Replacement%20Path%20Variables.html

  • How to calculate number of days between two date in Template design?

    Hello guys
    I have a situation where I have to create a template that returns data, and one of the thing of the existing report is that there is a column that is actually the number of days between start date and end date columns..
    So in template, how would I be able to do the same? I have start date and end date columns on the template, now when I created another column using expression like end date - start date and preview the template, I am getting errors saying :
    Caused by: oracle.xdo.parser.v2.XPathException: Cannot convert 03/31/2009 to number.
         at oracle.xdo.parser.v2.XSLStylesheet.flushErrors(XSLStylesheet.java:1534)
         at oracle.xdo.parser.v2.XSLStylesheet.execute(XSLStylesheet.java:521)
         at oracle.xdo.parser.v2.XSLStylesheet.execute(XSLStylesheet.java:489)
         at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:271)
         at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:155)
         at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:192)
    Please advice
    Thanks

    Hi
    There is an extension function you can use, from the javadoc:
    date_diff
    public static long date_diff(java.lang.String format,
    java.lang.String fromDate,
    java.lang.String toDate,
    java.lang.String locStr,
    java.lang.String tzID)
    Method to get the difference between two dates in the given locale. The dates need to be in "yyyy-MM-dd" format. This function supports only Gregorian calendar.
    Parameters:
    format - the format to which the difference is required; allowed formats are y (for Year), m(for month), w(for week), d(for day), h(for hour), mi(for minute), s(for seconds) and ms(for milliseconds)
    fromDate - the first date
    toDate - the second date
    locStr - locale string -> lang-Territory
    tzID - timezone ID ->http://java.sun.com/j2se/1.4.2/docs/api/java/util/TimeZone.html
    Returns:
    the difference in dates in the desired format
    For example
    <?xdoxslt:date_diff(‘d’,’2009-09-14’, ‘2009-09-20’,’en-US’,1)?>
    give a result of 6
    You can substitute in columns for the dates, just remember the date format required.
    Regards
    Tim

  • How to calculate number of days from a date field

    Dear BW Experts.
    I have a field 'Create Date' in the BEx query. Now we need to create a variable which should give the number of days from the date of running the query (sy-datum) to the Create Date.
    This will help the users to get records which are say, 30 days old (Sy-datum - create date = 30) or 10 days old etc.
    Could you suggest as to how to create this variable.
    Thanks,
    Sai

    Hi,
    Step 1: Create variable on "Create Date" with User entry processing type
    Step 2: Create a restricted KF for Sales & restrict it on "Create Date" to get "Sales on day"
    Step 3: Manipulate  the values of "Create Date" on which you could restrict  "Sales" again and again to get other values
    Step 4: Create one variable (ZPUTMNTH) for u201CMonth to Dateu201D with processing by u201CCustomer Exitu201D. This variable was created  on u201CDateu201D characteristics.
    Step 5 : Goto C-mod t-code and use EXIT_SAPLRRS0_001
    to calculate "month to date" user input is "Calday" Key Date
    WHEN 'ZPUTMNTH'.
    IF I_STEP = 2. "after the popup
    LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE
    WHERE VNAM = 'ZPDATE'.
    CLEAR L_S_RANGE.
    L_S_RANGE-LOW = LOC_VAR_RANGE-LOW(6). "low value, e.g.YYYYMM (200606) part of key date (20060625)
    L_S_RANGE-LOW+6(2) = '01'. u201C low value e..g. YYYYMM01 (20060601)
    L_S_RANGE-HIGH = LOC_VAR_RANGE-LOW. "high value = input
    L_S_RANGE-SIGN = 'I'.
    L_S_RANGE-OPT = 'BT'.
    APPEND L_S_RANGE TO E_T_RANGE.
    EXIT.
    ENDLOOP.
    ENDIF.
    Assign if helps.....
    Regards,
    Suman

  • How to calculate number of days between Calendar objects

    Hi,
    I need to calculate the number of days between two Calendar objects. Here is some sample code:
    Calendar now = Calendar.getInstance();
    now.set(Calendar.HOUR_OF_DAY, 0);
    now.set(Calendar.MINUTE, 0);
    now.set(Calendar.SECOND, 0);
    now.set(Calendar.MILLISECOND, 0);
    // get a calendar that represents a day in the past
    Calendar aDayInThePast = getADayInThePast();
    aDayInThePast.set(Calendar.HOUR_OF_DAY, 0);
    aDayInThePast.set(Calendar.MINUTE, 0);
    aDayInThePast.set(Calendar.SECOND, 0);
    aDayInThePast.set(Calendar.MILLISECOND, 0);
    // how can I calculate the number of days ago this was??
    //it would also be useful to get back a negative number if the day is in the future

    My favorite answer so far is reply 15 by Marc__: http://forum.java.sun.com/thread.jspa?threadID=488668&start=15

Maybe you are looking for

  • Buying a mid 2010 15" MacBook Pro

    Is there any sense to buy 4 years old MacBook Pro for 700 euros? It should last for me at least another 4 years and run Photoshop CS6, Final Cut Pro etc. Specs: MacBook Pro 15" Mid2010 - 15" Hi-Res antiglare (1680 x 1050) - 2,4 GHz Intel Core i5 - 8

  • WSImport-Error generating server code from existing wsdl ends in ERROR

    Hi, we have an existing wsdl, and need to change the Server Env. I am evaluating JAX-WS and WSImport, and it seems to be cool, but i have a Problem similar to this thread here: http://forum.java.sun.com/thread.jspa?threadID=739918&messageID=4245176 I

  • Issue in Offset Setting

    Hello, I have calenderday as characteristic. i need to display reportin following format Priority      Calday         keyfigures After180    02/08/2012  12                   03/09/2012   8 within 180  01/08/2011   0                   08/08/2012   0 A

  • Looks like Beta 3 is just around the corner...

    If you haven't noticed, things have changed on the Project Siena home page: http://www.microsoft.com/en-us/projectsiena/default.aspx Take a careful look and you'll also see a .zip with Beta 3 for the release notes and several updated references / doc

  • How can I change the input key language between different languages ?

    the language can't be changed when i press ctrl+alt