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.

Similar Messages

  • 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 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 the data as per accounting year

    I want to dispaly the result for  the accounting year from April to March for any accounting year (Accounting year is from April to March).
    I have a table INVOICE.
    CREATE TABLE INVOICE
      IN_NO       NUMBER,
      IN_DT       DATE,
      IN_DETAILS  VARCHAR2(20 BYTE)
    I want to calculate display the result for accounting year from April 2010 to March 2011, and from April 2011 to MArch 2012.
    What statement should i use to filter the data as above ?
    Sanjay

    user12957777 wrote:
    I want to dispaly the result for  the accounting year from April to March for any accounting year (Accounting year is from April to March).
    I have a table INVOICE.
    CREATE TABLE INVOICE
    IN_NO       NUMBER,
    IN_DT       DATE,
    IN_DETAILS  VARCHAR2(20 BYTE)
    I want to calculate display the result for accounting year from April 2010 to March 2011, and from April 2011 to MArch 2012.
    What statement should i use to filter the data as above ?
    Sanjay
    You should learn now to use correct tags
    select to_char(add_months(in_dt,-3),'YYYY') FISCAL_YEAR FROM INVOICE;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • 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

  • 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

  • How to calculate number of days between fixed date and hire date in schema

    i want to calculate the number of days between a fixed date en the hire date (infotype 041)
    If i read the documentation  right, i should use the following command:
    HRS=YDXA02
    Variable 3 (the x) is the fixed data.
    My question is how do i program the variable x?
    Let's say the date 01.01.2008
    Any help would be welcome

    I assume we are talking about PCR for payroll. In this case look at documentation for operation NUM:
    OOOOOO
    Xnnnnn
    X     Table
    nnnnn Table field
    nn    Date type 'nn' from the Date Specifications infotype (0041)
         Date types are taken from table T548Y.
    Your operation would look like:
      NUM=Faaesb
          F          Fixed indicator for deadline calculation
           aa           Date type: Start date of period to be
                        calculated; if the date type is not 'nn,'
                        the second position is left blank.
             e          Unit, in which the duration is calculated:
                        T = days
                        W = week
    s         End date of period to be calculated:
              (blank)  End of current payroll period
              J        End of current calendar year
              A        Start of current calendar year
              B        Start of WPBP period
             No other specifications are possible.
    So it depends on what kind of fixed date you need.
    Hope it helps,
    Carlos.

  • 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 previous business day

    Hi,
    I'm stuck with an issue.
    Task is to calculate 1 to 6 previous business days with reference to system date.
    Conditions are : Week is 6 day. In first case its Sunday as weekend holiday and in second case its Saturday as weekend holiday.
    Another condition is I have to take care of bank holidays also which are stored in a separate table in database.
    How to implement this logic ?
    Below I have implemented some logic but its not running correctly for some dates adjusted according to bank holidays.
    In this code I'm taking Sunday as weekend off and To_Date is having the list of bank holidays for 2012.
    SELECT
      CASE
        WHEN TRUNC(SYSDATE-1) IN (TO_DATE('01-JAN-2012'), TO_DATE('02-JAN-2012'), TO_DATE('07-APR-2012'), TO_DATE('09-APR-2012'), TO_DATE('07-MAY-2012'), TO_DATE('04-JUN-2012'), TO_DATE('05-JUN-2012'), TO_DATE('27-AUG-2012'), TO_DATE('25-DEC-2012'), TO_DATE('26-DEC-2012'))
        THEN (
          CASE
            WHEN TRUNC(SYSDATE-2) IN (TO_DATE('01-JAN-2012'), TO_DATE('02-JAN-2012'), TO_DATE('07-APR-2012'), TO_DATE('09-APR-2012'), TO_DATE('07-MAY-2012'), TO_DATE('04-JUN-2012'), TO_DATE('05-JUN-2012'), TO_DATE('27-AUG-2012'), TO_DATE('25-DEC-2012'), TO_DATE('26-DEC-2012'))
            Then (
            CASE
            WHEN TRUNC(SYSDATE-3) IN (TO_DATE('01-JAN-2012'), TO_DATE('02-JAN-2012'), TO_DATE('07-APR-2012'), TO_DATE('09-APR-2012'), TO_DATE('07-MAY-2012'), TO_DATE('04-JUN-2012'), TO_DATE('05-JUN-2012'), TO_DATE('27-AUG-2012'), TO_DATE('25-DEC-2012'), TO_DATE('26-DEC-2012'))
            Then (
            CASE
            WHEN TRUNC(SYSDATE-4) IN (TO_DATE('01-JAN-2012'), TO_DATE('02-JAN-2012'), TO_DATE('07-APR-2012'), TO_DATE('09-APR-2012'), TO_DATE('07-MAY-2012'), TO_DATE('04-JUN-2012'), TO_DATE('05-JUN-2012'), TO_DATE('27-AUG-2012'), TO_DATE('25-DEC-2012'), TO_DATE('26-DEC-2012'))
            Then (       
            CASE
            WHEN TRUNC(SYSDATE-5) IN (TO_DATE('01-JAN-2012'), TO_DATE('02-JAN-2012'), TO_DATE('07-APR-2012'), TO_DATE('09-APR-2012'), TO_DATE('07-MAY-2012'), TO_DATE('04-JUN-2012'), TO_DATE('05-JUN-2012'), TO_DATE('27-AUG-2012'), TO_DATE('25-DEC-2012'), TO_DATE('26-DEC-2012'))
            Then (       
            CASE
            WHEN TRUNC(SYSDATE-6) IN (TO_DATE('01-JAN-2012'), TO_DATE('02-JAN-2012'), TO_DATE('07-APR-2012'), TO_DATE('09-APR-2012'), TO_DATE('07-MAY-2012'), TO_DATE('04-JUN-2012'), TO_DATE('05-JUN-2012'), TO_DATE('27-AUG-2012'), TO_DATE('25-DEC-2012'), TO_DATE('26-DEC-2012'))
            THEN DECODE(TO_CHAR((SYSDATE-6),'DAY'),'MONDAY   ',TRUNC((SYSDATE-6)-7),'TUESDAY  ',TRUNC((SYSDATE-6) - 7),'WEDNESDAY',TRUNC((SYSDATE-6) - 7),'THURSDAY ',TRUNC((SYSDATE-6) - 7),'FRIDAY   ',TRUNC((SYSDATE-6) - 7),'SATURDAY ',TRUNC((SYSDATE-6) - 7),'SUNDAY   ',TRUNC((SYSDATE-6) - 6))
            ELSE DECODE(TO_CHAR((SYSDATE-5),'DAY'),'MONDAY   ',TRUNC((SYSDATE-5)-7),'TUESDAY  ',TRUNC((SYSDATE-5) - 7),'WEDNESDAY',TRUNC((SYSDATE-5) - 7),'THURSDAY ',TRUNC((SYSDATE-5) - 7),'FRIDAY   ',TRUNC((SYSDATE-5) - 7),'SATURDAY ',TRUNC((SYSDATE-5) - 7),'SUNDAY   ',TRUNC((SYSDATE-5) - 6))
            END)
            ELSE DECODE(TO_CHAR((SYSDATE-4),'DAY'),'MONDAY   ',TRUNC((SYSDATE-4)-7),'TUESDAY  ',TRUNC((SYSDATE-4) - 7),'WEDNESDAY',TRUNC((SYSDATE-4) - 7),'THURSDAY ',TRUNC((SYSDATE-4) - 7),'FRIDAY   ',TRUNC((SYSDATE-4) - 7),'SATURDAY ',TRUNC((SYSDATE-4) - 7),'SUNDAY   ',TRUNC((SYSDATE-4) - 6))
            END)
            ELSE DECODE(TO_CHAR((SYSDATE-3),'DAY'),'MONDAY   ',TRUNC((SYSDATE-3)-7),'TUESDAY  ',TRUNC((SYSDATE-3) - 7),'WEDNESDAY',TRUNC((SYSDATE-3) - 7),'THURSDAY ',TRUNC((SYSDATE-3) - 7),'FRIDAY   ',TRUNC((SYSDATE-3) - 7),'SATURDAY ',TRUNC((SYSDATE-3) - 7),'SUNDAY   ',TRUNC((SYSDATE-3) - 6))
            END)
            ELSE DECODE(TO_CHAR((SYSDATE-2),'DAY'),'MONDAY   ',TRUNC((SYSDATE-2)-7),'TUESDAY  ',TRUNC((SYSDATE-2) - 7),'WEDNESDAY',TRUNC((SYSDATE-2) - 7),'THURSDAY ',TRUNC((SYSDATE-2) - 7),'FRIDAY   ',TRUNC((SYSDATE-2) - 7),'SATURDAY ',TRUNC((SYSDATE-2) - 7),'SUNDAY   ',TRUNC((SYSDATE-2) - 6))
          END )
              ELSE DECODE(TO_CHAR((SYSDATE-1),'DAY'),'MONDAY   ',TRUNC((SYSDATE-1)-7),'TUESDAY  ',TRUNC((SYSDATE-1) - 7),'WEDNESDAY',TRUNC((SYSDATE-1) - 7),'THURSDAY ',TRUNC((SYSDATE-1) - 7),'FRIDAY   ',TRUNC((SYSDATE-1) - 7),'SATURDAY ',TRUNC((SYSDATE-1) - 7),'SUNDAY   ',TRUNC((SYSDATE-1) - 6))
          END)
        ELSE DECODE(TO_CHAR((SYSDATE),'DAY'),'MONDAY   ',TRUNC((SYSDATE)-7),'TUESDAY  ',TRUNC((SYSDATE) - 7),'WEDNESDAY',TRUNC((SYSDATE) - 7),'THURSDAY ',TRUNC((SYSDATE) - 7),'FRIDAY   ',TRUNC((SYSDATE) - 7),'SATURDAY ',TRUNC((SYSDATE) - 7),'SUNDAY   ',TRUNC((SYSDATE) - 6))
      END
    FROM DUAL;Edited by: user9082359 on Oct 21, 2012 8:55 PM

    Hello,
    There are two business streams.
    For one stream,Saturday is holiday and for other Sunday is holiday and
    ('01-JAN-2012'), ('02-JAN-2012'), ('07-APR-2012'), ('09-APR-2012'), ('07-MAY-2012'), ('04-JUN-2012'), ('05-JUN-2012'), ('27-AUG-2012'), ('25-DEC-2012'), ('26-DEC-2012') is my list of bank holidays for 2012 year.
    Now if suppose we have to calculate 1 previous business day for today 22 Oct,it would be 20 Oct for one stream and 21 Oct for another stream.
    Like this I have to calculate 1-6 previous business days for sysdate.
    Now If there is a bank holiday coming in between e.g. suppose 20 Oct is a bank holiday and Sunday is weekend holiday,so now 1 previous business day would be 19 Oct.
    I hope I have made myself clear.
    Thanks and waiting for solution of this issue.

  • 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

  • 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

  • Confused - How to Calculate Number of Days Between Dates but Exclude Weekend Dates If There Hasn't Been a Weekend Update

    Hello -
    I've been tearing my hair out over this problem i'm trying to solve, probably just been staring at it too long which is making it worse -
    I have a series of open support tickets which are supposed to be updated on a daily basis, the problem is that they aren't always being updated daily.  So, the business wants to know the number of days from when a ticket was last updated and today's
    date.  I have this basic calculation and it's working fine, however now the business wants to exclude weekends from the calculation.  The other problem is that some reps DO go in on weekends and update their tickets, so sometimes there will be updates
    made on weekend dates.
    To give an example -
    Today's date is 2014-02-10 (Monday).  A ticket was last updated last Thursday, 2014-01-30.  The difference between the two dates is 11, so it's been 11 days since the ticket was last updated.  Now, if I exclude Saturdays and Sundays, then
    it's actually been 7 days since the ticket was last updated.  I'm not sure how to do this in T-SQL.
    Now, to further complicate the problem, sometimes a ticket IS updated on a Saturday or Sunday.  So, if a ticket was updated on 2014-02-02 (Sunday), then it should be counted.  Again i'm not sure how to do this. 
    What gets me is that this is probably fairly simple and i've just been staring at it too long.  In the meantime, can someone offer some guidance?
    Thanks!!

    I've adapted this from a function on my blog. you will need to add set the YourTicketTable to where ever your tickets are stored.
    CREATE
    FUNCTION [dbo].[CalcWorkDaysBetween](@StartDate
    As DateTime,@EndDate
    AS DateTime)
    RETURNS
    INT AS
    BEGIN
    SET @EndDate
    =DATEADD(DAY,1,@EndDate)
    DECLARE @Count
    AS Int= 0
    DECLARE @Date
    As Date=@StartDate
    WHILE @Date
    < @EndDate
    BEGIN
    IF (DATEPART(WEEKDAY,@Date)IN(1,7)
    OR (SELECT
    Count(*)
    FROM YourTicketTable WHERE TicketDate=@Date)=1)
    BEGIN
    SELECT @Count = @Count
    + 1
    END
    SELECT @Date=DATEADD(Day,
    1,@Date)
    END
    RETURN
    DATEDIFF(DAY,@StartDate,@EndDate)- @Count
    END
    Regards,

  • How to calculate No. Received days in BEx

    Hello Gurus,
    I have requirement as, need to calculated the number of days from received date. My data model is like as below,
    I have a multi provider ZMP_01 which gets gets data from 2 cubes, ZCU_01 and ZCU_02 and this ZCU_02 cube has a field called "Source System" and this filed will have data "ZDSO_05", "ZDSO_06", "ZDSO_07", "ZDSO_08".
    Now i need to caluculate the number of days (Current date - received date) for those whose Souce System is "ZDSO_05" & "ZDSO_07".
    Reveived data is one of the time characteristic in Multi Provider whic maintain 0CREATEDON for the item.
    I required your kind advise/help ASAP.
    thanks in advance
    Peter

    Hi,
    you can do it by using Formula Variable with Replacement path and simple Cstomer Exit Variable, you can see the following Artcile, in the same way you can do it.
    Calculating the Ageing of the Materials
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/business-intelligence/a-c/calculating%20the%20ageing%20of%20the%20materials.pdf
    Thanks
    Reddy

Maybe you are looking for