Calculating days excluding weekends

Msy you please show me how to calculate the number of days in between 2 dates excluding weekends.

Hi!
Check out these FM-s:
K_ABC_WORKDAYS_FOR_PERIODS_GET
WEEK_GET_NR_OF_WORKDAYS      
WLB3_GET_NUMBER_OF_WORKDAYS  
There are some calendar relevant FM-s also. If there's set a production calendar in your SAP, you can check it also.
SE37 transaction, and search for CALENDAR fm.
Regards
Tamá

Similar Messages

  • ICal custom repeat every x days EXCLUDING weekends?

    I have an event I would like to repeat every x number of days excluding weekends (so only counting M-F as "counted" days). Is there a way to do this?

    You can exclude Sat/Sun, but they will still be counted - so an occurrence on those days is dropped, and you will get fewer occurrences than you should.
    AK

  • ABAP HR- calculation of workind days (excluding weekend) for an employee

    Hi,
    I need to get number of working days between two dates excluding weekends for an employee. Please let me know below questions in this regard:
    1. I have to use Factory calender or holiday calender for this purpose?
    2. Will FM RKE_SELECT_FACTDAYS_FOR_PERIOD solve this purpose ?
    Regards,
    Aleria

    Hi Aleria,
    Use the FM DAY_ATTRIBUTES_GET in this FM pass the holiday and factory calendar of the employee along with the period. In the output structure if free day is set then it is SAT/SUN and if holiday is set then it is Public holiday marked in the calendar.
    Regards
    Bala

  • Fucntion to Calculate business days (exclude weekends & holidays) between two days

    Hello,
    I need to be able to calculate business days between two dates excluding weekends and holidays. I do have a date dimension and also flags which denote weekday, holiday. Would really appreciate help in building a udf for the business days calculation.
    Thanks,

    Hi, Please take a look and tweak accordingly. Best of luck.
    --Assuming data dimension table something like the following
    --tblDateDim (DT date primary key,
    flagHoliday bit,
    flagWeekday bit
    CREATE FUNCTION fnBusinessDays (
    @StartDate DATE,
    @EndDate DATE
    RETURNS INT
    AS
    BEGIN
    DECLARE @Days INT ;
    SELECT @Days = count(*)
    FROM tblDateDim --// date dimension
    WHERE
    ( DT BETWEEN @StartDate AND @EndDate) --// dt is date column in the table.
    AND --// also flags which denote weekday, holiday
    flagHoliday = 0 --// flagHoliday= 1--Holiday;= 0 --workingday/businessday
    AND
    flagWeekday = 1 --// FlagWeekday = 1--businessday ; =0 --weekend (Saturday and Sunday)
    RETURN (@Days)
    END
    GO

  • 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

  • Delivery Date should propose only working days (Excluding weekends and holidays

    Hello All
    I have one requirement here, where delivery dates should propose only working days and it should not allow to add weekends and holidays during the creation of sales order.
    I would like to know if there are any standard settings to be done in plant or shiping point?
    Kindly need all your input on this
    Thanks
    Naveen

    Hello All
    Same calendar has already been assigned in shipping point,plant and sales org and also in the calendar holidays been maintained, even though when we create a sales order it will accept weekends and holidays
    Thanks

  • Finding the number of days excluding weekends

    Dear All,
    I want to find the date difference between the working days,
    ex, take 2 dates, today - Monday 11th and Monday 18th,
    So, I want a function module which will calculate the difference between working days, means from 18th to 11th, it should calculate the difference as 5 working days.
    Please let me know the function module which will show the number of difference in working days.
    Thanks in Advance,
    Ramana

    Hi,
    Check the following code:
    REPORT ZDATEDIFF.
    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

  • 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,

  • Add working days to a date excluding weekends and holidays

    Hi there,
    I need to write a function that will take a specified date and number of days to add as input parameters, and return the working day based on the number of days to add parameter, excluding weekends and any holidays held in a holiday table.
    Here is my function so far -
    CREATE OR REPLACE FUNCTION f_add_work_days(pd_date IN DATE
    ,pn_add_days IN PLS_INTEGER) RETURN DATE IS
    pd_in_date DATE := pd_date;
    ld_next_holiday DATE;
    ln_days_left PLS_INTEGER := pn_add_days;
    CURSOR cu_holiday(pn_date IN ge740.holdte%TYPE) IS
    SELECT pck_utility.f_dtcnv(g.holdte)
    FROM ge740 g
    WHERE g.holdte >= pn_date
    AND g.maint <> 'D'
    ORDER BY g.holdte ASC;
    BEGIN
    OPEN cu_holiday(pck_utility.f_dtcnv(pd_in_date));
    FETCH cu_holiday
    INTO ld_next_holiday;
    CLOSE cu_holiday;
    LOOP
    IF ln_days_left = 0 THEN
    EXIT;
    END IF;
    pd_in_date := pd_in_date + 1;
    IF pd_in_date > ld_next_holiday THEN
    OPEN cu_holiday(pck_utility.f_dtcnv(pd_in_date));
    FETCH cu_holiday
    INTO ld_next_holiday;
    CLOSE cu_holiday;
    END IF;
    CASE
    WHEN TO_CHAR(pd_in_date
    ,'fmDAY') = 'SATURDAY' THEN
    pd_in_date := pd_in_date + 2;
    ln_days_left := ln_days_left - 1;
    WHEN TO_CHAR(pd_in_date
    ,'fmDAY') = 'SUNDAY' THEN
    pd_in_date := pd_in_date + 1;
    ln_days_left := ln_days_left - 1;
    WHEN pd_in_date = ld_next_holiday THEN
    pd_in_date := pd_in_date + 1;
    ln_days_left := ln_days_left - 1;
    ELSE
    ln_days_left := ln_days_left - 1;
    END CASE;
    END LOOP;
    RETURN(pd_in_date);
    END f_add_work_days;
    I think there is something wrong/missing in the logic as I can't get it to cater for say a double bank holiday(25/26th Dec - if the input parameters are 24/12/2007 and 2, which should return the 28th but returns the 26th!!).
    I'm relatively new to PL/SQL and Oracle, so any help, advice, ideas would be greatly appreciated!
    thanks in advance

    smth like
    SQL> with holidays as (select to_date('10.06.2007','dd.mm.yyyy') h_dt from dual),
      2       par as (select to_date('08.06.2007','dd.mm.yyyy') dt, 2 add_days from dual)
      3  --
      4  select min(dt) needed_date
      5    from (select p.*,
      6                 h.*,
      7                 mod(to_char(dt, 'j'), 7),
      8                 sum(decode(mod(to_char(dt, 'j'), 7), 5, 0, 6, 0, 1)+--get rid of sat and sun
      9                     nvl2(h_dt, -1, 0)--check if the day is holiday
    10                     ) over(order by dt) s
    11            from (select dt + level dt, add_days
    12                    from par
    13                  connect by level <= 100) p,
    14                 holidays h
    15           where h_dt(+) = dt
    16           order by 1)
    17   where add_days = s
    18  /
    NEEDED_DATE
    13.06.2007
    SQL> ?
    Message was edited by:
    Volder
    PS What Oracle version are you on?

  • Working day formula that excludes weekends and holidays in WEBI

    Hi Guys,
    Can we calculate a working day formula that excludes weekends and holidays in WEBI OR in Universe?
    The universe I am working on is using stored procedures, so there are no joins or modelling done. Although there is a workday stored proc  that I can bring in the universe.
    I am just thinking if there is no modelling or joins done in the universe how will this help me in webi?
    Your suggestions will be very helpful.
    Thanks,
    Jitan

    One more suggestion I need from you  -
    I have a Work_Calendar_VW that has the following columns -
    Calendar_Date - 5/1/2014
    Calendar_Year - 2014
    Calendar_Month - 5
    Calendar_Day - 1
    Work_Day - 1
    Day_Type - WD (Work Day)  For Weekends this will be displayed as WE
    The columns have all dates for current year in SQL Server.
    I am going to pull this into the universe and create 2 derived tables to calculate MTD Day counts.
    Derived Table 1  - Calculate Yest Work Day... this will remove all the weekends and holidays and give me the last working day. This includes couple of case statments to check each day if it's a working day or weekend.
    For Work Day the above code will be 1 and for weekend 0
    Derived Table 2  - This will give me the count of working days in current month using the above view and Derived table 1 Below is the code  -
    SELECT COUNT(*)
    FROM Work_Calendar_VW
    WHERE [Work_Day] = 1 AND
       (Calendar_Date BETWEEN CAST(CONVERT(VARCHAR(25),MONTH(LastWoringkday()),101) + '/01/'
       + CONVERT(VARCHAR(25),YEAR(LastWoringkday()),101) AS DATE)
      AND LastWoringkday()).
    I cannot do joins because this universe has been built using stored proc and would like to implement this in BO universe.
    let me know if this is the right approach.
    Thanks,
    Jitan

  • 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

  • Time between dates excluding Weekends and Holidays

    I am fairly new to Power Pivot and I am having trouble with this formula.  I need my Cycle Time Days column to capture the days between CreatedDataTime and ClosedDateTime excluding Weekends and Holidays.  I have a tab that has the holidays but
    I can't get the formula correctly?   Jill
    CreatdDateTime        ClosedDateTime     Cycle Time Days
    12/1/2014                    12/10/2014

    first of all you need a separate time table which holds all possible dates for your model
    there should be no gaps, it should contain full years and a column of datatype DateTime as unique key
    once you have this in place add a calculated column to this table as 
    =IF(INT(FORMAT([Date], "w")) >= 6, "Weekend", "Workday")
    then go back to your original table and add the following calculation for your [Cycle Time Days]-column:
    =COUNTROWS(
    FILTER(
        'Dates',
        Dates[Date] >= DateRanges[DateFrom]
        && Dates[Date] <= DateRanges[DateTo]
        && 'Dates'[IsWeekend] = "Workday"
    Holidays are a bit more tricky but you can follow the same pattern but you need to get the holidays from somewhere
    hth,
    -gerhard
    Gerhard Brueckl
    blogging @ http://blog.gbrueckl.at
    working @ http://www.pmOne.com

  • Excluding Weekend dates from Select

    Hi all,
    I have a select statement that returns the average number of days a job stays at a particular status. What I want to do is to exclude weekend dates from the calculation. I am using oracle 10..
    My select statement looks like this when I look for status that is on New by taking the difference of the end_date and start_date that are not null. However this include the weekend dates as well so how do I exclude weekend dates from the computation.
    SELECT
    AVG ( SUM ( ( DECODE (STATUS, 'New', end_date, NULL ) -
    DECODE ( STATUS, 'New', start_date, NULL ) ) ) )
    FROM TBL
    on a table that is defined as
    CREATE TBL (varchar STATUS, DATE start_date, DATE end_date)
    Thank you

    Lucky for us, TO_DATE takes a 3rd parameter. My Test:
    ALTER SESSION SET NLS_DATE_LANGUAGE = 'DUTCH'
    ALTER SESSION SET NLS_TERRITORY = 'THE NETHERLANDS'
    WITH yourtable AS
       SELECT TO_DATE('01-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('02-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('03-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('04-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('05-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('06-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('07-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('08-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('09-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('10-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('11-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('12-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('13-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('14-04-2007','dd-mm-yyyy')  col_1 FROM dual
    SELECT TO_CHAR(col_1, 'D') D
         , TO_CHAR(col_1, 'DD-MM') thedate
    FROM yourtable
    WITH yourtable AS
       SELECT TO_DATE('01-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('02-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('03-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('04-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('05-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('06-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('07-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('08-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('09-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('10-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('11-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('12-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('13-04-2007','dd-mm-yyyy')  col_1 FROM dual UNION ALL
       SELECT TO_DATE('14-04-2007','dd-mm-yyyy')  col_1 FROM dual
    SELECT TO_CHAR(col_1, 'Dy', 'NLS_DATE_LANGUAGE=ENGLISH') x
         , TO_CHAR(col_1, 'DD-MM') y
    FROM yourtable
    WHERE TO_CHAR(col_1, 'DY', 'NLS_DATE_LANGUAGE=ENGLISH') NOT IN ('SAT','SUN')
    /My run:
    SQL> @orafaq
    Session altered.
    Session altered.
    D THEDA
    7 01-04
    1 02-04
    2 03-04
    3 04-04
    4 05-04
    5 06-04
    6 07-04
    7 08-04
    1 09-04
    2 10-04
    3 11-04
    D THEDA
    4 12-04
    5 13-04
    6 14-04
    14 rows selected.
    X   Y
    Mon 02-04
    Tue 03-04
    Wed 04-04
    Thu 05-04
    Fri 06-04
    Mon 09-04
    Tue 10-04
    Wed 11-04
    Thu 12-04
    Fri 13-04
    10 rows selected.

  • Exclude weekend query

    Hi expert,
    I already create udf for date start( u_start ) and date end ( u_end ) column in SO,i just want to know how to create simple query that can exclude weekend like saturday and sunday, example from 2/5/2011 until 25/11/2011 has 24 days,so i want minus all weekend like saturday and sunday,so i can get 18 day,can someone help me about this......

    Hi Pari,
    i want to create in query only not in crystal report,in sales order
    Hi Gordon,
    Its just calculation only right?  this example query i try
    SELECT DATEDIFF(dd,u_start,u_end) - DATEDIFF(dd,u_start,u_end)*2/7 'Days without weekend' from ordr where docnum = 281
    when i choose start date 1/12/2011 and end date 4/12/2011 it calculate 3 days,it suppose to be 2 days if without saturday and sunday as weekend
    thanks for your help
    regards,
    Arif

  • Exclude weekends when substracting between two date values

    Hi All,
    I created a variable to get the value between 2 date values.
    v_lag_days := TRUNC (l_header_rec.request_date) - TRUNC (SYSDATE);
    if l_header_rec.request_date = sysdate i.e. 17-Feb-12 then it is fine, I will get the value as '0' which is correct.
    But if l_header_rec.request_date = '20-Feb-12' (for example), it will give me as '3', but I should get the value as '1' excluding weekends.
    When ever with in the 2 date values if it contains weekends, it should exclude those weekend days and should give me the value in the variable.
    If you are not able to get my point clearly, please let me know.
    Could anyone please let me know the logic for my scenario. Please help me out that would be really appreciated.
    Thanks in advance,
    Satya.

    Hi Satya.
    This is the same example, without including the final day.
    WITH aux1 AS
         SELECT
              CASE WHEN TO_NUMBER(TO_CHAR(TO_DATE(:date1,'YYYYMMDD')+(LEVEL-1),'D')) >= 6
                   THEN 0
                   ELSE 1
              END inc
         FROM dual
         CONNECT BY LEVEL <= (TO_DATE(:date2,'YYYYMMDD') - TO_DATE(:date1,'YYYYMMDD'))
    SELECT SIGN(:date2 - :date1)*SUM(inc) num_of_days FROM aux1;
    -- ':date2 = 20120217'
    -- ':date1 = 20120210'
    NUM_OF_DAYS
              5
    -- ':date2 = 20120220'
    -- ':date1 = 20120217'
    NUM_OF_DAYS
              1
    -- ':date2 = 20120217'
    -- ':date1 = 20120217'
    NUM_OF_DAYS
              0Hope this helps.
    Best Regards
    Edited by: sKr on 17-feb-2012 9:04 Improved for date2 = date1

Maybe you are looking for