Calculating Business Days(Start_dt - End_dt)

Hi Friends,
Could anyone of you help me to find out the business days(Excluding Saturdays and Sundays) between two dates.
The difference should be calculated of both the Start_dt and End_dt values truncated. The result should be calculated and stored according to business days, it means weekend days are to be ignored.
create table sample (id number,start_dt date,end_dt date). The table values are as follows;
ID ; start_dt ; End_dt
1 ; 08-02-2012 ; 15-02-2012
2 ; 30-12-2011 ; 15-02-2012
My output should be;
ID ; start_dt ; End_dt ; Expected Business Days (Excluding Weekends)
1 ; 08-02-2012 ; 15-02-2012 ; 4
2 ; 30-12-2011 ; 15-02-2012 ; 33
Please note that, the Start Date and End Date can be any date from any year. Please help me on this.
Regards,
Williams.
Edited by: Williams on Feb 8, 2012 6:28 PM
Edited by: Williams on Feb 8, 2012 6:29 PM

Here's my first cut at it.
SQL> WITH sample AS
  2  (
  3     SELECT 1 AS id, TO_DATE('08-02-2012','DD-MM-YYYY') AS start_dt, TO_DATE('15-02-2012','DD-MM-YYYY') AS end_dt FROM DUAL UNION ALL
  4     SELECT 2 AS id, TO_DATE('30-12-2011','DD-MM-YYYY') AS start_dt, TO_DATE('15-02-2012','DD-MM-YYYY') AS end_dt FROM DUAL
  5  )
  6  /* END SAMPLE DATA */
  7  SELECT id
  8       , start_dt
  9       , end_dt
10       , COUNT(*)
11  FROM   sample
12  JOIN   ( /* Exclude Weekends */
13           SELECT dt
14           FROM  ( /* Generate a range that includes all days */
15                   SELECT min_start_dt + (LEVEL - 1) AS dt
16                        , TO_CHAR
17                          ( min_start_dt + (LEVEL - 1)
18                          , 'fmDAY'
19                          , 'NLS_DATE_LANGUAGE=AMERICAN'
20                          ) AS dy
21                   FROM   ( SELECT MIN(start_dt) AS min_start_dt
22                                 , MAX(end_dt)   AS max_end_dt
23                            FROM   sample
24                          )
25                   CONNECT BY LEVEL <= max_end_dt - min_start_dt + 1
26                 )
27           WHERE dy NOT IN ('SATURDAY','SUNDAY')
28         ) dys ON dys.dt BETWEEN start_dt AND end_dt
29  GROUP BY id
30         , start_dt
31         , end_dt
32  /
        ID START_DT            END_DT                COUNT(*)
         2 12/30/2011 00:00:00 02/15/2012 00:00:00         34
         1 02/08/2012 00:00:00 02/15/2012 00:00:00          6
2 rows selected.I got different results then you though. Can you say why your counts are what they are?

Similar Messages

  • Calculating Business Days in a Date Range

    I have two questions:
    1. Does anyone know a better formula for calculating business days in totals?
    I am currently using the formula in https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/701a52c3-6b1e-2b10-21b3-a6e101be1a0f
    I tailored to my needs.  However, there are still a lot of manual maintenance every year. 
    2. I have many reports that need the formula.  It is very consuming to update the formula in each report.  Does anyone know a better way to do it? 
    I use Crystal XI. 11.0.0.895.  We do have a Crystal Enterprise server hosted in another department.

    Not sure if this is any simpler but you could save this as a custom function, that way you will have to modify it once a year for the holidays.
    numbervar days;
    datevar date1 := minimum({?My Parameter});
    datevar date2 := maximum({?My Parameter});
    days := DateDiff ("d", date1, date2) -
    DateDiff ("ww", date1, date2, crSaturday) -
    DateDiff ("ww", date1, date2, crSunday);    // this will give you the number of business days
                                                        // (excluding Saturdays and Sundays) for a given date range.
    // then, for each holiday, you can enter lines like this
    if date(2008,01,01) in {?My Parameter} then days := days - 1;
    // The final tally of DAYS should give you the total business days in a date range.
    totext(days,0);
    where {?My Parameter} is the date range.

  • Need Help Calculating Business Days AND omitting Holidays...

    Post Author: dkotenoglou
    CA Forum: Formula
    Thanks to the people here I was able to get a nice formula to help me calculate the amount of business days between two days.//Crystal syntax
    Local DateTimeVar d1 := ;
    Local DateTimeVar d2 := ;
    DateDiff ("d", d1, d2) -
         DateDiff ("ww", d1, d2, crSaturday) - 
         DateDiff ("ww", d1, d2, crSunday) This works great.  I wanted to add the ability to omit US Holidays.  Now this is a straight Crystal Reports install without an SQL backend so I cannot use any formulas there.Is there a parameter? I can use to manually create a table of dates to omit?  The only reason I ask is that our company was closed during the holidays so my day reports are really high. I do not mind typing a long list of days manually (12/24/2007, 12/25/2007, etc) but I need to know how to best integrate that list into the formula.  

    Post Author: V361
    CA Forum: Formula
    If you have CR XI, there is another example as well, in the sample reports,  look at feature examples, custom functions.rpt   this code is from that example.
    Function cdDateAddSkipHolidays (nWorkingDays As Number, startDateTime As DateTime) As DateTime    'the result = startDateTime + nWorkingDays + nHolidays (including weekends)    'the algorithm below also works when nWorkingDays is negative
        Dim totalDays    'give a rough estimate for total days. For each 5 work days there are 7    'days. Also add in an extra 2 weekend days to account for a partial week.    totalDays = Fix(nWorkingDays * 7 / 5 + 1) + 2
        Dim iteratedDiff    iteratedDiff = cdDateDiffSkipHolidays (startDateTime, startDateTime + totalDays)
        If (iteratedDiff >= nWorkingDays) Then        Do While iteratedDiff >= nWorkingDays            totalDays = totalDays - 1            iteratedDiff = cdDateDiffSkipHolidays (startDateTime, startDateTime + totalDays)        Loop        cdDateAddSkipHolidays = startDateTime + totalDays + 1    Else        Do While iteratedDiff < nWorkingDays            totalDays = totalDays + 1            iteratedDiff = cdDateDiffSkipHolidays (startDateTime, startDateTime + totalDays)        Loop         cdDateAddSkipHolidays = startDateTime + totalDays    End If
    End Function

  • Calculation of due date based on Business Days for FICA documents

    Hi All,
    I am working on project where SD - FICA integration is in picture. We post some charges through SD and FICA document gets posted on relevant Contract Account.
    Normally we create Sales Order using transaction VA01 and then we do Billing for this Sales Order through VF01. After billng is done, FICA document automatically gets generated.
    We have following requirement to be fulfilled.
    For the SD bills posted as above, I want to calculate due date of these bills based on Business Days for FICA document generated (SAP Standard calculate due date based on Calander days). We can use factory calander for calculating business days in relevant function module.
    I have checked in the system and it seems that event 1330 ( FM - ISU_DUE_DATE_DETERMINE) is not working in this scenario. Is there any other FM which I can use?
    Can anyone help me on this?
    Regards,
    Pradeep

    Hello Praeva ,
    The event 1330 has a sample FM FKK_SAMPLE_1330. It doesnt even have a Standard Function Module.
    You need to create a Installation-Specific FM and put your code to determine the Due Date based on the logic.
    Rgds
    Ram Kumar.

  • Baseline date calculation excluding non-Business days

    Hi,
    We have a requirement to exclude non-Business days while calculating Baseline date.
    Currently the Baseline Date being populated in the Accounting Document is Document date + 5days(including Holidays).
    For eg
    Current Scenario
    Document Date: 12th Feb 2008
    Baseline date: 17th feb 2008.
    Requirement:
    Document Date: 12th Feb 2008
    Baseline date: 19th feb 2008(Excluding Sat & Sun).
    Request you to share useful info in this regard.
    Thanks
    Binu

    Hi,
    Use user exit RV60FUS5 for these base line date calculations.
    Thanks
    Krishna.

  • Calculation of Business day in OBIEE

    Hi,
    How to calculate the business day in OBIEE by excluding both weekends and public holidays.
    Please guide me

    If you want the "nth business day," here is something I prepared.
    Understanding the Concept in Layman Terms
    The first step to deriving the calculation is looking at a calendar. For our example, we will calculate the 6th business day of each month.
    1) Observation One: When the first day of the month is Saturday, the 6th business day occurs when “today’s date minus the first-day-of-the month equals 9.”
    2) Observation Two: When the first day of the month is Sunday, the 6th business day occurs when the above calculation equals 8.
    3) Observation Three: When the first day of the month is Monday – Friday, the 6th business day occurs when the above calculation equals 7.
    Building the SQL
    Below are the SQL statements that correspond to the above observations:
    4) When the first day of the month is Saturday…
    DAYOFWEEK(TIMESTAMPADD(SQL_TSI_DAY,DAYOFMONTH(CURRENT_DATE)*-1,CURRENT_DATE)) = 6 AND DAYOFMONTH(CURRENT_DATE)-DAYOFMONTH(TIMESTAMPADD(SQL_TSI_DAY,1,TIMESTAMPADD(SQL_TSI_DAY,DAYOFMONTH(CURRENT_DATE)*-1,CURRENT_DATE))) = 9
    5) When the first day of the month is Sunday…
    DAYOFWEEK(TIMESTAMPADD(SQL_TSI_DAY,DAYOFMONTH(CURRENT_DATE)*-1,CURRENT_DATE)) = 7 AND DAYOFMONTH(CURRENT_DATE)-DAYOFMONTH(TIMESTAMPADD(SQL_TSI_DAY,1,TIMESTAMPADD(SQL_TSI_DAY,DAYOFMONTH(CURRENT_DATE)*-1,CURRENT_DATE))) = 8
    6) When the first day of the month is Monday – Friday…
    DAYOFWEEK(TIMESTAMPADD(SQL_TSI_DAY,DAYOFMONTH(CURRENT_DATE)*-1,CURRENT_DATE)) NOT IN (6,7) AND DAYOFMONTH(CURRENT_DATE)-DAYOFMONTH(TIMESTAMPADD(SQL_TSI_DAY,1,TIMESTAMPADD(SQL_TSI_DAY,DAYOFMONTH(CURRENT_DATE)*-1,CURRENT_DATE))) = 7
    Putting the SQL Statements Together
    When any of the above conditions are true (“OR” between each condition), then (THEN) “today” is the 6TH business day; otherwise (ELSE) it is not the 6th business day. Below is the final SQL:
    CASE WHEN
    DAYOFWEEK(TIMESTAMPADD(SQL_TSI_DAY,DAYOFMONTH(CURRENT_DATE)*-1,CURRENT_DATE)) = 6 AND DAYOFMONTH(CURRENT_DATE)-DAYOFMONTH(TIMESTAMPADD(SQL_TSI_DAY,1,TIMESTAMPADD(SQL_TSI_DAY,DAYOFMONTH(CURRENT_DATE)*-1,CURRENT_DATE))) = *9*
    OR
    DAYOFWEEK(TIMESTAMPADD(SQL_TSI_DAY,DAYOFMONTH(CURRENT_DATE)*-1,CURRENT_DATE)) = 7 AND DAYOFMONTH(CURRENT_DATE)-DAYOFMONTH(TIMESTAMPADD(SQL_TSI_DAY,1,TIMESTAMPADD(SQL_TSI_DAY,DAYOFMONTH(CURRENT_DATE)*-1,CURRENT_DATE))) = *8*
    OR
    DAYOFWEEK(TIMESTAMPADD(SQL_TSI_DAY,DAYOFMONTH(CURRENT_DATE)*-1,CURRENT_DATE)) IN (1,2,3,4,5) AND DAYOFMONTH(CURRENT_DATE)-DAYOFMONTH(TIMESTAMPADD(SQL_TSI_DAY,1,TIMESTAMPADD(SQL_TSI_DAY,DAYOFMONTH(CURRENT_DATE)*-1,CURRENT_DATE))) = *7*
    THEN '6th Business Day' ELSE 'Not 6th Business Day' END
    Modifying the Query for the nth Business Day
    To modify the above SQL for the nth business day, change the numbers in bold to the appropriate values.

  • Subtract business days from date - calculated column

    Hello,
    I had a calculated column on a library that took two dates and found the difference between them in business days, but I am not sure how to subtract business days from a date...for instance I get a start date from a form and I need to
    subtract 10 business days from that date.
    Can anyone help?

    I've always resorted to Javascript/JQuery for that kind of function. I found an old fashioned loop worked the best for me - it supports going forward or backwards. I key it off of a change in a starting date, or sometimes a status change. My actual production
    code takes into account another list where we remove holidays and non-work days.
    newDate = getNextDate(newDate, -3);
    $("input[title='Date Due']").val((newDate.getMonth() + 1) + "/" + newDate.getDate() + "/" + newDate.getFullYear());
    function getNextDate(currentDate, offset) {
    // offset is business days
    var wkend = 0;
    var index = Math.abs(offset); // need positive number for looping
    var neg = true;
    if(offset >= 0) { neg = false; }
    var curDOW = currentDate.getDay();
    var nextDate = new Date(currentDate);
    for(var i=1; i <= index; i++) {
    nextDate.setDate(nextDate.getDate() + (neg ? -1: 1));
    var nextDOW = nextDate.getDay();
    if(nextDOW == 0) {nextDate.setDate(nextDate.getDate() + (neg ? -2: 1));} // Sunday
    if(nextDOW == 6) {nextDate.setDate(nextDate.getDate() + (neg ? -1: 2)); } // Sat
    // alert("offset is " + offset + "start: " + currentDate + ", next date is " + nextDate);
    return nextDate;
    Robin

  • Oracle 8i: Business Days Calculation in a Subquery

    To Whom It May Concern:
    I apologize if this has been posted already, but I didn't find any threads that address my issue:
    I need to find the number of business days between 2 dates (excludes weekends) provided by dates from an outer query such as the following:
    SELECT
         C.CUSTOMER_ID
         , C.ENTRY_DATE
         , C.COMPLETION_DATE
         , <SOME SUBQUERY HERE THAT CALCULATES THE NUMBER OF BUSINESS DAYS BETWEEN C.COMPLETION_DATE AND C.ENTRY_DATE> AS BUSINESS_DAYS
    FROM CUST_TABLE C
    Thanks for your time and advice.
    Max

    you don't need a subquery. it's a very simple formula
    Re: query regarding dates
    (you may need to change the case to a decode for v8 - I don't remember when it was introduced)

  • Business Day Calculation

    I would like to add x number of business days to a date extracted from Discoverer Plus. How might one do so?

    Hi,
    I think passing v_nextBusinessDate for checking holiday will solve your problem. Please refer bold lines.
    create or replace function getNextBusinessDay(IN_DATE date)
         return date
         is
              v_nextBusinessDate date;
              v_isAHoliday boolean;
         begin
              v_isAHoliday := false;
              v_nextBusinessDate := IN_DATE;
              loop
                   v_isAHoliday := check_holiday(v_nextBusinessDate);
                   if (v_isAHoliday = false)
                   then
                        exit;
                   else
                        v_nextBusinessDate := v_nextBusinessDate+ 1;
                   end if;
              end loop;
              return v_nextBusinessDate ;
         end;

  • Calculating hours in numerical formats between 2 business days, calculated column

    Hi there,
    I need to calculate how many hours are between 2 days only including business days, outputting in numerical format (ex. 7.3). 
    I've been using this formula to output how many weekdays are between 2 days.
    =IF(AND((WEEKDAY(CompletedTimeStamp,2))<(WEEKDAY(,2)),((WEEKDAY(Created,2))-(WEEKDAY(CompletedTimeStamp,2)))>1),(((DATEDIF(Created,CompletedTimeStamp,"D")+1))-(FLOOR((DATEDIF(Created,CompletedTimeStamp,"D")+1)/7,1)*2)-2),(((DATEDIF(Created,CompletedTimeStamp,"D")+1))-(FLOOR((DATEDIF(Created,CompletedTimeStamp,"D")+1)/7,1)*2)))
    The problem with this is if the 2 dates are on the same day, it outputs "1". I need it to output the amount of hours then / by 24 to give me ".7"  instead.
    Is there anything I can do to convert this current formula to give me hours instead of days?
    Thanks,
    Terence

    The DATEDIF is rounding to the nearest day.
    Try this:
    =IF(AND((WEEKDAY(CompletedTimeStamp,2))<(WEEKDAY(,2)),((WEEKDAY(Created,2))-(WEEKDAY(CompletedTimeStamp,2)))>1),(((CompletedTimeStamp-Created+1))-(FLOOR((CompletedTimeStamp-Created+1)/7,1)*2)-2),(((CompletedTimeStamp-Created+1))-(FLOOR((CompletedTimeStamp-Created+1)/7,1)*2)))
    -1
    Then above will return fractions of days, i.e.  5.5 days. Multiply this by 24 for hours.
    I think there is a extra "+1" in the above example somewhere, so I added a minus 1 to get back the correct value.
    Hi.. Mike.. I am trying to use this calcuation.. its renndering "time being used 3.3".. I need it to calcuate a work day as 8 hrs  so if
    Start Date= 9/12/2014 9:00am
    End Date= 9/16/2014 5:00 pm
    should be 3 (8 hr work days)  any way I can fix this?
    Thanks in advance for your help.
    Mike Smith TechTrainingNotes.blogspot.com

  • Add number of business days to date field

    Hello, I noticed that there is not much discussion in the forum surrounding u201Cbusiness daysu201D so I hope this post/discussion/solution contributes to the content of this forum.
    I am using the following 3 formulas to try to Add number of business days (based upon a table field) to a specified date:
    1. Variable name = SetVar
    //Set Variable for Add Business Days:
    DateVar Array Holidays;
    DateVar Target:= CDate({TMS_MOVEMENT_EVT.EVT_DATE}); // Put your field name in here
    NumberVar Add:=  {DTCI_DOD_TRANS.TRANS}; // put the number of days here to add (a positive number)
    NumberVar Added := (0);
    2. Variable name = AddBizDays
    //Adding Business Days:
    EvaluateAfter({@SetVar});
    WHILE Added < Add
    Do (target := target +1;
        if dayofweek (target) in 2 to 6 and not (target in holidays)
            then Added:=Added+1
            else Added:=Added);
    Target
    3. Variable name = HOLIDAYS
    //Holiday Array Formula for the report Header:
    BeforeReadingRecords;
    DateVar Array Holidays := [
    Date (2003,12,25),   // you can put in as many lines for holidays as you want. 
    Date (2003,12,31)
    0
    I am successfully getting my data needed to make the necessary calculations and variable assignmentsu2026 I believe that my ISSUE is that I am not sure where to place these formulas into my report so they assign the variables and execute properly when previewing my report. I am curious if that is my issue, and if so, can someone provide me direction on where to put each of these formulas in my report.
    Currently, when I try to preview the report, I get the following Crystal Reports Error:  -u201CA number, currency amount, Boolean, date, time, date-time, or string is expected here.u201D
    Then Crystal automatically opens the AddBizDays formula and highlights the word added, see below RE: u201CWHILE Addedu201D
    For reference, my report has 3 groups, and I am displaying all of my output information (and locating my formulas) in the group footer #3 report section. I have moved them around to other report sections/groups/placements, but to no success.
    Thanks so much.
    Best, Matt

    I worked this out... FYI - for the benefit of all forum users:
    ADDING BUSINESS DAYS TO A CERTAIN DATE (excluding weekends and holidays)
    1. Variable name = AddBizDays
    //Adding Business Days:
    WhileReadingRecords;
    DateVar Array Holidays;
    DateVar Target:= CDate(); // Put your field name in here
    NumberVar Add:=  ; // put the number of days here to add (a positive number)
    NumberVar Added := (0);
    WHILE Added < Add
    Do (target := target +1;
        if dayofweek (target) in 2 to 6 and not (target in holidays)
            then Added:=Added+1
            else Added:=Added);
    Target
    2. Variable name = HOLIDAYS
    //Holiday Array Formula for the report Header:
    BeforeReadingRecords;
    DateVar Array Holidays := [
    Date (2003,12,25), // you can put in as many lines for holidays as you want.
    Date (2003,12,31)
    0
    ...too bad i don't get forum points for sharing this solution.
    Special thanks to KenHamady.com -- for sharing this solution.
    Sincerely,
    Matt

  • Formula to calculate due date considering only business days (Middle East)

    I have a form which contains two fields: 'Start Date' and 'Completion Date'; the 'Completion Date' field is automatically set, it's always 3 more days than the 'Start Date' field.
    The problem is that these 3 days must be only business days.
     - if 'Start Date' is on Sunday then the 'Completion Date' should be set to next Wednesday
     - if 'Start Date' is on Monday then the 'Completion Date' should be set to next Friday
     - if 'Start Date' is on Tuesday then the 'Completion Date' should be set to next Sunday
     - if 'Start Date' is on Wednesday then the 'Completion Date' should be set to next Monday
     - if 'Start Date' is on Thursday then the 'Completion Date' should be set to next Tuesday
     - if 'Start Date' is on Friday then the 'Completion Date' should be set to next Tuesday
     - if 'Start Date' is on Saturday then the 'Completion Date' should be set to next Tuesday
    Friday and Saturday should be ignored as 'Completion Date' (weekend in Middle East).
    Anyone has any idea of how to make this formula? I need to put it into a calculated SharePoint column.
    Thanks in advance for your help.

    Hi
    check my post
    http://www.romeodonca.ro/Lists/DB_IT/Adding%20a%20number%20of%20working%20days%20to%20a%20specific%20date
    If you need more details let me know
    Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.

  • 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

  • Is there a function to derive "business days" only

    Is there either an Oracle SQL built-in function or user-defined function for calculating the difference
    between two dates or between SYSDATE and a date in the database, which uses business days
    only (at least excluding weekends)?
    I'd appreciate any help on this!
    Thanks!
    Kathy Kuehnle
    [ [email protected] ]

    We solved this with the following package:
    create or replace
    package body zentr_date_functions as
      function eastern (p_year in number) return date is
        -- Calculate easter sunday (valid from 1900 to 2099)
        -- based on a Gauss algorithm
        l_a pls_integer;
        l_b pls_integer;
        l_c pls_integer;
        l_d pls_integer;
        l_e pls_integer;
        l_p pls_integer;
        function make_date(p_d in pls_integer, p_m in pls_integer, p_y in pls_integer) return date is
        begin
          return to_date(to_char(p_d, '00')||to_char(p_m, '00')||to_char(p_y, '0000'), 'DDMMYYYY');
        end;
      begin
        if p_year not between 1900 and 2099 then
          return null;
        end if;
        l_a := mod(p_year, 19);
        l_b := mod(p_year, 4);
        l_c := mod(p_year, 7);
        l_d := mod(19 * l_a + 24, 30);
        l_e := mod(2 * l_b + 4 * l_c + 6 * l_d + 5, 7);
        l_p := 22 + l_d + l_e;
        if l_p > 31 then
          if l_p = 56 and l_d = 28 and l_a > 10 then
            return make_date(18, 4, p_year);
          elsif l_p = 57 then
            return make_date(19, 4, p_year);
          else
            return make_date(l_p - 31, 4, p_year);
          end if;
        else
          return make_date(l_p, 3, p_year);
        end if;
      end eastern;
      function is_workday (p_date in date) return number as
        -- Is p_date a working day?
        l_eastern date;
      begin
        if to_char(p_date, 'DY', 'NLS_DATE_LANGUAGE = AMERICAN') in ('SAT', 'SUN') then
          return 0;
        end if;
        if to_char(p_date, 'DDMM') in ('0101', '0105', '0310', '2412', '2512', '2612', '3112') then
          return 0; -- fixed bank holidays in lower saxony, Germany
        end if;
        if to_number(to_char(p_date, 'MM')) not between 3 and 6 then
          return 1;
        end if;
        if to_number(to_char(p_date, 'YYYY')) not between 1900 and 2099 then
          return null;
        end if;
        l_eastern := eastern (to_number(to_char(p_date, 'YYYY')));
        if trunc(p_date) in (l_eastern - 2, l_eastern + 1, l_eastern + 39, l_eastern + 50) then
          return 0; -- eastern depentent bank holidays in lower saxony, Germany
        end if;
        return 1;
      end is_workday;
      -- This is what you are looking for:
      function workdays_between (p_date1 in date, p_date2 in date) return number as
        -- count number of workdays between p_date1 and p_date2 (both p_date1 and p_date2 included).
        l_count pls_integer := 0;
      begin
        for i in 0 .. p_date2 - p_date1 loop
          l_count := l_count + is_workday(p_date1 + i);
        end loop;
        return l_count;
      end workdays_between;
    end;

  • Setting Due Date for task using business days

    While this may not be new news to many, I found little information on how to add a certain number of business days to determine the due date for a task to be used in a workflow.  For SharePoint 2010 environments that cannot run custom code, I have
    found a solution that utilizes two additional columns in the task list.  The first column I named
    Deadline (a number with no decimal places), which will contain the number of business days until a task is to be completed.
    The second I named Business Deadline (a calculated column returning a
    Date and Time).  The formula for the calculated column is:
    =[Modified]+INT(ROUNDDOWN([Deadline]/5,0)*7)+ IF(WEEKDAY([Modified]+MOD([Deadline],5))<MOD([Deadline],5), IF(WEEKDAY([Modified]+MOD([Deadline],5)+2)=7,MOD([Deadline],5)+4, IF(WEEKDAY([Modified]+MOD([Deadline],5)+2)=1,MOD([Deadline],5)+3,MOD([Deadline],5)+2)), IF(WEEKDAY([Modified]+MOD([Deadline],5))=7,MOD([Deadline],5)+2, IF(WEEKDAY([Modified]+MOD([Deadline],5))=1,MOD([Deadline],5)+1,MOD([Deadline],5))))
    The workflow on create in the task list then is:
    Set Deadline to {number of business days}
    then Wait for Deadline to equal {number of business days} 'Necessary to ensure the Business Deadline has been set
    'then Set Due Date to CurrentItem:Business Deadline
    Hope this helps a few others that are beating their heads against their desks like I was.

    Hi,
    Glad to hear that you solve this issue, thanks for your sharing.
    Thanks,
    Linda Li
    Linda Li
    TechNet Community Support

Maybe you are looking for