Function, procedure to find next "x" business days

Hi,
Is there any function procedure to find next 10 business days in oracle.
Also i have a local holiday table which are non-working days.
Thanks.

Hi,
Ramin showed how to get the next 10 days.
If you want to exclude holidays and weekends, and get only the 10th day, then you can do something like this:
WITH     next_hundred_days     AS
     SELECT  TRUNC (SYSDATE) + LEVEL          AS bnsdate
     FROM      dual
     CONNECT BY     LEVEL <= 100
,     work_days          AS
     SELECT     n.bnsdate
     ,     ROW_NUMBER () OVER (ORDER BY bnsdate)     AS day_num
     FROM           next_hundred_days  n
     LEFT OUTER JOIN      holidays         h  ON  h.dt  = n.bnsdate
     WHERE   TO_CHAR ( bnsdate
               , 'Dy'
               , 'NLS_DATE_LANGUAGE=ENGLISH'
               )     NOT IN ('SAT', 'SUN')
     AND     h.dt          IS NULL
SELECT  bnsdate
FROM     work_days
WHERE     day_num     = 10
;This assumes that there will be at least 10 work days in the next 100 days. Where I work, that's a very safe assumption.
I hope this answers your question.
If not, post CREATE TABLE and INSERT statements for a few rows from your holiday table.
Post a few (starting date, number of days) pairs, and the results that you would want from each pair, given the data you posted in the holiday table.
See the forum FAQ {message:id=9360002}

Similar Messages

  • Function, procedure to find next 10 business days

    Hi,
    Is there any function procedure to find next 10 business days in oracle.
    Also i have a local holiday table which are non-working days.
    Thanks.

    user7987260 wrote:
    Hi,
    Is there any function procedure to find next 10 business days in oracle.
    Also i have a local holiday table which are non-working days.
    Thanks.Welcome to OTN!
    This forum is for PL/SQL Developer questions. SQL and PL/SQL questions have their own forum that you can find under the Oracle Database heading. You should get a better answer if you ask your question there

  • How can i find the 1st business day of the week ?

    Hi,
    How can i find the 1st business day of the week excluding saturaday,sunday and holidays? i have holiday table which contains the columns name HolidayDate and HolidayDescription.
    Ex:
    10-1-2011 is monday(i.e) 1st business day.check If it is in holiday table,then return the result as 11-1-2011 else return the result as 11-1-2011(which is the first business day of this week).
    Can anyone tell me the Query to solve it?

    Does this help:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (SELECT TRUNC(SYSDATE,'IW') holiday FROM dual
      2  UNION SELECT TRUNC(SYSDATE + 7,'IW') from dual)
      3  SELECT MIN(Dat),wk FROM
      4  (SELECT TO_CHAR(dat,'IW') wk,dat FROM
      5  (SELECT dat + lvl dat FROM
      6  (SELECT TRUNC(SYSDATE,'RRRR') dat, level - 1 lvl
      7  FROM dual
      8  CONNECT BY level <= TO_DATE('31-DEC'||TO_CHAR(SYSDATE,'RRRR')) - TRUNC(SYSDATE,'RRRR'))
      9  ) x
    10  WHERE x.dat NOT IN (select holiday from t))
    11  WHERE TO_CHAR(Dat,'DY') <> 'SAT'
    12  AND TO_CHAR(dat,'DY') <> 'SUN'
    13* group by wk
    SQL> /
    MIN(DAT)  WK
    04-JAN-11 01  -- since 03-JAN-2011 is in holiday list, 04 is taken as first business day of first week
    11-JAN-11 02  -- similar to week 1
    17-JAN-11 03
    24-JAN-11 04
    31-JAN-11 05
    07-FEB-11 06
    14-FEB-11 07
    21-FEB-11 08
    28-FEB-11 09
    07-MAR-11 10
    14-MAR-11 11
    21-MAR-11 12
    28-MAR-11 13
    04-APR-11 14
    11-APR-11 15
    18-APR-11 16
    25-APR-11 17
    02-MAY-11 18
    09-MAY-11 19
    16-MAY-11 20
    23-MAY-11 21
    30-MAY-11 22
    06-JUN-11 23
    13-JUN-11 24
    20-JUN-11 25
    27-JUN-11 26
    04-JUL-11 27
    11-JUL-11 28
    18-JUL-11 29
    25-JUL-11 30
    01-AUG-11 31
    08-AUG-11 32
    15-AUG-11 33
    22-AUG-11 34
    29-AUG-11 35
    05-SEP-11 36
    12-SEP-11 37
    19-SEP-11 38
    26-SEP-11 39
    03-OCT-11 40
    10-OCT-11 41
    17-OCT-11 42
    24-OCT-11 43
    31-OCT-11 44
    07-NOV-11 45
    14-NOV-11 46
    21-NOV-11 47
    28-NOV-11 48
    05-DEC-11 49
    12-DEC-11 50
    19-DEC-11 51
    26-DEC-11 52
    52 rows selected.
    SQL>

  • How to run procedure/job only on third business day of the month

    Hello All,
    how can i run the procedure/job only third business day of the month? I am using month table in my procedure and it gets updated only once in month and procedure doesn't need to run everyday.

    >
    how can i run the procedure/job only third business day of the month? I am using month table in my procedure and it gets updated only once in month and procedure doesn't need to run everyday.
    >
    For such a sparse schedule the easiest way is to DBMS_SCHEDULER and set the 'repeat_interval' using the BYDATE parameter.
    See Table 14-7 in chapter 114 DBMS_SCHEDULER of the PL/SQL Packages and Types doc
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_sched.htm#BABEJGCH
    >
    Table 114-7 Values for repeat_interval
    BYDATE
    This specifies a list of dates, where each date is of the form [YYYY]MMDD. A list of consecutive dates can be generated by using the SPAN modifier, and a date can be adjusted with the OFFSET modifier. An example of a simple BYDATE clause is the following:
    BYDATE=0115,0315,0615,0915,1215,20060115
    The following SPAN example is equivalent to BYDATE=0110,0111,0112,0113,0114, which is a span of 5 days starting at 1/10:
    BYDATE=0110+SPAN:5D
    The plus sign in front of the SPAN keyword indicates a span starting at the supplied date. The minus sign indicates a span ending at the supplied date, and the "^" sign indicates a span of n days or weeks centered around the supplied date. If n is an even number, it is adjusted up to the next odd number.
    Offsets adjust the supplied date by adding or subtracting n days or weeks. BYDATE=0205-OFFSET:2W is
    >
    The chapter has examples.

  • Number of business days (excluding holidays) ?

    Hi All,
    What is the SQL query to find number of business days (excluding holidays) between 2 given dates ?
    List of Holidays will be maintained as a separate table.
    I need a SQL query rather than a stored procedure or function.
    I am using oracle 9i.
    Thanks in advance.

    Does this thread help?
    Need to find number of business days - query pls

  • 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

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

  • Get Next business day conditionally

    Hi All,
    I have a calendar table with all federal holidays, saturdays and sundays flagged to 1.
    I need help in finding the next business day from givendate and that too Conditionallly.. means
    Lets say today's date is 01/02/2014(wednesday) and I want to know the next businessday after 10 days which would be 01/16/2014(thursday). Exclude saturdays and sundays in between.
    I started like this..but gives me wrong date..
    Also, when 10th day is saturday or sunday or any holiday it should give next business day.
    so i need help in tweaking my query.
    select NextBusinessDay = min(a.Date)+10
    from  [dbo].[Calendar] a
    where
     a.Date > GETDATE() 
     and a.day_Name not in ('Saturday','Sunday')
     and a.IsHoliday <> 1
    Thanks,
    RH
    sql

    Try this out:
    DECLARE @calendar TABLE (date DATE, holiday BIT, weekend BIT)
    DECLARE @i INT = 0
    SET NOCOUNT ON
    WHILE @i < 50
    BEGIN
    INSERT INTO @calendar (date, holiday, weekend)
    VALUES (DATEADD(DAY,@i,'2014-01-01'),0,CASE WHEN DATEPART(WEEKDAY,DATEADD(DAY,@i,'2014-01-01')) IN (1,7) THEN 1 ELSE 0 END)
    SET @i = @i + 1
    END
    UPDATE @calendar SET holiday = 1 WHERE date = '2014-01-20'
    SET NOCOUNT OFF
    SELECT max(date)
    FROM (
    SELECT TOP 10 *
    FROM @calendar
    WHERE date > '2014-01-02'
    AND holiday <> 1
    AND weekend <> 1
    ) a
    Obviously I've simulated your calendar, and forced a date into it.

  • 3 Years Next Business Day On-Site Warranty Registration

    Hello,
    I bought a warranty extension for my laptop, it is a warranty for 3 Years Next Business Day On-Site service. Now i tried to register the service and it reqognized de certificate number I gave. But when i finished with putting in my serial key, adress and all that, I was said that the registration couldn't be fully completed without a copy of the receipt i got when i bught the warranty.
    Now that wouldn't be so hard right, except for the fact that there was no e-mail adress given for me to send a copy of my receipt to. So could i get the e-mail adress where i'm supposed to send it to, please?

    If you check this section you can find many threads with e-mail address where you can contact Toshiba.
    By the way contact details can be found at http://eu.computers.toshiba-europe.com/innovation/contact_toshiba.jsp

  • Not giving paid for next business day service

    Hi Has anybody got a number I can phone in the uk for customer complaints? My nine month old thinkpad screen went. Company paid for extra next business day service for repairs. At first they said they didn't have a replacement and it would take an unknown amount of time to find one. When I asked to speak to a supervisor they found one.Next business day then became two days later because they sent out requests to all engineers by 3pm. I had the contract in front of me saying they had to receive the call by 4pm. They said sorry there is nothing they could do about it. Why bother paying for next day - poor service for a premium price.

    Hello MacLux,
    I was disappointed to read that your order wasn't processing in line with the communications you'd received. I apologize for any inconvenience to you.
    Using the information you provided when you signed up for Best Buy Unboxed, I was able to locate your order. I note that your order was cancelled shortly after you posted your message. It also seems that a new order was placed early this morning. For the new order, the shipment is currently awaiting pickup from our warehouse by the carrier.
    If you have questions or concerns, please let me know. I'm very grateful that you wrote to us.
    Sincerely,
    John|Social Media Specialist | Best Buy® Corporate
     Private Message

  • 5. We need additional time to process your transaction You should get an email from us by next business day. If you don't hear back from us, you can check your order status on your account page or call us at +1 800-585-0774. If you're not in North America

    Step 5.
    5. We need additional time to process your transaction You should get an email from us by next business day. If you don't hear back from us, you can check your order status on your account page or call us at +1 800-585-0774. If you're not in North America, you can look up a local number here. For now, check out all the great free features of Creative Cloud! Get started with trials
    I keep getting this.
    The Bank and Paypal states that Adobe needs to process my transaction twice.
    I have no order number/ no status nor contact from Adobe. I called customer service and he transferred me to sales where the phone rang with no answer.

    Since this is an open forum, not Adobe support... you need to contact Adobe staff to help
    Adobe contact information - http://helpx.adobe.com/contact.html
    -Select your product and what you need help with
    -Click on the blue box "Still need help? Contact us"
    -or by telephone http://helpx.adobe.com/x-productkb/global/phone-support-orders.html

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

  • Function Module to find the day

    Hi,
    I have a date S_DATE with me.
    I need to find the day of that date.
    I hope there is a function module for this.
    Please reply me if you know the name of the Function Module to find the date.
    Thanks in advance.

    Hi Rajesh,
    Thanks for the reply. Your answer solved my problem.

  • Function to get business days

    hi
    version oracle 10g
    Function should accept start date and business_days_to_add and it should return date.
    to a given date i want to add business_days(business days are all days except SAT SUN)
    lets say i want to add 4 business days to sysdate then function should return date as 09/16/2010thanks

    One way of doing it:
    CREATE OR REPLACE FUNCTION add_business_days(p_date IN DATE, p_bus_days IN NUMBER) RETURN DATE DETERMINISTIC IS
      v_return DATE;
    BEGIN
      WITH t AS
       (SELECT rownum rn, trunc(p_date) + decode(sign(p_bus_days), 1, LEVEL - 1, -1, (LEVEL * -1) + 1, 0) theday
          FROM dual
         WHERE to_char(p_date + decode(sign(p_bus_days), 1, LEVEL - 1
                                                       ,-1, (LEVEL * -1) + 1
                                                       , 0), 'DY', 'NLS_DATE_LANGUAGE=ENGLISH') NOT IN ('SAT', 'SUN')
               OR ROWNUM = 1
        CONNECT BY rownum <= abs(p_bus_days) + 1)
      SELECT theday
        INTO v_return
        FROM t
       WHERE rn = abs(p_bus_days) + 1;
      RETURN v_return;
    END;Sample execution:
    SQL> CREATE OR REPLACE FUNCTION add_business_days(p_date IN DATE, p_bus_days IN NUMBER) RETURN DATE DETERMINISTIC IS
      2    v_return DATE;
      3  BEGIN
      4    WITH t AS
      5     (SELECT rownum rn, trunc(p_date) + decode(sign(p_bus_days), 1, LEVEL - 1, -1, (LEVEL * -1) + 1, 0) theday
      6        FROM dual
      7       WHERE to_char(p_date + decode(sign(p_bus_days), 1, LEVEL - 1
      8                                                     ,-1, (LEVEL * -1) + 1
      9                                                     , 0), 'DY', 'NLS_DATE_LANGUAGE=ENGLISH') NOT IN ('SAT', 'SUN')
    10             OR ROWNUM = 1
    11      CONNECT BY rownum <= abs(p_bus_days) + 1)
    12    SELECT theday
    13      INTO v_return
    14      FROM t
    15     WHERE rn = abs(p_bus_days) + 1;
    16    RETURN v_return;
    17  END;
    18  /
    Function created
    SQL> select add_business_days(sysdate, 5) from dual;
    ADD_BUSINESS_DAYS(SYSDATE,5)
    17/9/2010
    SQL> select add_business_days(sysdate, -55) from dual;
    ADD_BUSINESS_DAYS(SYSDATE,-55)
    25/6/2010
    SQL> select add_business_days(sysdate+1, 1) from dual;
    ADD_BUSINESS_DAYS(SYSDATE+1,1)
    13/9/2010
    SQL> select add_business_days(sysdate+1, -1) from dual;
    ADD_BUSINESS_DAYS(SYSDATE+1,-1
    10/9/2010
    SQL> Edited by: fsitja on Sep 10, 2010 12:49 PM Fixed to take into account negative numbers.

  • How can i find out the next 2 working days.

    Hi Experts,
    Based on a given date, i would like to find out the next 2 working days.
    Help me out.
    Regards,
    Mansi.

    Hi,
    Use this FM WRF_PSCD_GET_NEXT_WORKDAY
    first get the first working day and pass that day again to get the next working day
    and also pass the calender id for the same
    Import parameters               Value
    I Import parameters               Value
    I_DATE                          09/15/2007
    I_CALENDAR1                     US
    I_CALENDAR2
    Export parameters               Value
    E_WORKDAY                       09/17/2007
    Regards
    Shiva

Maybe you are looking for