Add Working Days Function

All,
I have created the following function to add working days to a date...
create or replace function add_working_days(
p_days in number,
p_dt in date default trunc(sysdate)
return date
as
v_weeks number;
v_adj number;
begin
v_weeks := trunc(p_days/5);
if to_number(to_char(p_dt,'D')) + mod(p_days,5) >= 7 then
v_adj := 2;
else
v_adj := 0;
end if;
return p_dt + 7*v_weeks + v_adj+mod(p_days,5);
end add_working_days;
I am then calling the function to default a date field.
The hassle is that it keeps setting the year to 0006 instead of 2006.
Any suggestions?
Cheers,
Gart

Gart,
I ran your code -
SQL> select sysdate from dual;
SYSDATE
24-JAN-06
SQL> select to_char(sysdate, 'Day') as Today from dual;
Today
Tuesday
SQL> select
  next_working_date,
  to_char(next_working_date, 'Day') as next_working_day
from
  (select add_working_days(4, sysdate) as next_working_date from dual)
SQL> /
NEXT_WORKING_DATE    NEXT_WORKING_DAY
30-JAN-06            MondaySo it seems to work for me, are you sure it's not your NLS settings or your date formatting code that isn't displaying the year correctly?

Similar Messages

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

  • When building a vacation leave holiday system using SharePoint Foundation 2010 and SharePoint Designer workflows how can I add half day functionality?

    Hi,
    I have built a vacation leave holiday system for SharePoint Foundation 2010 using SharePoint Designer workflows and Javascript. Everything works perfectly but I'm struggling to design a solution for users to specify half day requests that span over dates
    greater than 1 day, i.e. my half day solution works but only when the start and end date are the same. How would I change the user interface to allow users to choose which day they want the half day to be requested when the vacation leave holiday request is
    from, say,  6th - 10th Jan 2014?
    Thanks.

    Hi ,
    I have a test on my machine with a custom approval workflow and it can work normally .Here are the detailed steps :
    1.      
    Open the site in SharePoint Designer .Create a workflow to associate with the document library .Set the workflow to start when an item is created and when an item is changed
    .Also allow the workflow to start manually .
    2.      
    Choose ‘Collect Data from a user’ .
    3.      
    Click on the data and give a name to the Task created .
    4.      
    Define the custom form field name as ‘Approve ?’ .Set the information type as Choice .
    5.      
    Set the choices as ‘Approve’ and ’Reject’ .Display as Checkboxes .Uncheck the ‘Allow fill-in values’ and ‘Allow blank values’
    .Click finish to save .
    6.      
    Click on users and add the users who will approve the documents .
    7.      
    Keep the output to variable as collect .
    8.      
    Add a new step .Choose ‘If any value equals value ’ .Set the any value ‘Data source’ as  workflow variables and parameters .Set the ‘Field
    from source’ as Variable: collect .
    9.      
    Set the value behind ‘equals ’ as ‘Approve’ .
    10.  
    Add a new action ‘Update list item ’ .Set the item as current item .Add the field Approval status as Approved .
    11.  
    Add an Else-if branch to update the Approval status as Rejected .
    12.  
    Publish the workflow and test in your site .
    Thanks,
    Entan Ming

  • Add number of working days

    I have to subtract a number of 'working days' of a date field in my message mapping.
    I wrote a user defined function. I used cal.add(Calendar.DATE, -3); on the instance cal of the class Calendar. It subtracts 3 days, but I have to subtract 3 'working days'.
    Has anyone a suggestion how to achieve this?
    Kind regards
    Frank

    Frank,
        Since you said that there is FM available in R/3 DATE_CHECK_WORKINGDAY. I would suggest you to do RFC Lookup and get the response if it not working day, then subtract 1 from the current day, and again do lookup to check whether its working day or not. Finally if you get the response as Working day, then subtract 3 from the day(not from the current date, instead the subtracted date , in my previous step).
    But  it will not solve your issue. The above I said is an approach. Because, consider the below example.
    Current day is Saturday, you r doing RFC lookup and getting response as not-working day. Hence on subtracting 1 you will get Friday, now again you are doing RFC look up , this time you will get response as working day , immediately you will subtract 3 from friday, Finally you will get the result as tuesday!!!!
    Do you think its correct? Yah sometimes, because while subtracting 3 from friday we have to make sure that thursday & wednesday must not be holiday. I think you got my example, If I'm wrong , please reply me back.
    Hope it clears.
    The above is an approach, its not the solution. If you look its good we have to apply logic to ahieve the result.
    Best Regards,
    raj.

  • Adobe Muse (2014.3) "Add Web Font" Function Not Working As Expected - Newly Added Fonts Become Unavailable Though Shown

    Hello.
    This has also been posted in the Community: Adobe Muse Bugs forum.
    I've been having some odd/irregular issues though they have now become fairly predictable in nature. The issue is in regards to Adobe Muse (2014.3) and the availability of web fonts provided through the applications "Add Web Fonts" feature. Once added they perform as expected but then become "unavailable." Full details below. I have been a Creative Cloud Complete subscriber for a number of years so am fairly familiar with the way in which the system works minus a few issues that have popped up now and then, this one included.
    System Info:
    Adobe Creative Cloud (Full Subscription): Version 1.9.1.474
    Adobe Muse: Version 2014.3
    OS X Yosemite: 10.10.2
    Here is a recap of what has been taking place. I'll detail the bug as best I can.
    1. Created new Adobe Muse project. Everything normal.
    2. Chose to add a new font through the "Add Web Fonts" function within Muse. A note, my Creative Cloud App is running/open at all times (in file synch mode).
    3. Chose new fonts using above. All seemed fine (see screenshots below).
    4. Fonts also were indicated as being "Synched" within Creative Cloud (screenshot below).
    5. As expected the two fonts were added to the list of available Web Fonts within Muse (first screenshot below - left). I added them successfully to my site. Well after a number of hours I went back to this same font selection menu within Muse and the fonts were still visible yet the sub-menu that one would expect showing various forms (i.e. Bold, Italic, etc) was not available. In a sense the font could not be chosen from the list even though the name is clearly visible (second screenshot below - right).
    Have no idea what may have been wrong. Saved Muse project, closed and reopened - nothing changed. Created new project - fonts still "shown" in menu but can't be used. Did find a vague description using Google of similar problem (different application) which recommended closing Creative Cloud Desktop App and reopening as one possible solution. This DID WORK initially yet the problem, though corrected for a period of time (few hours at most), would reappear again where one would again see yet not be able to choose from the two Web Fonts. Went so far as to uninstalling the Creative Cloud Desktop application and reinstalling. Still have not solved the problem.
    Any thoughts as to what this may be would be welcome. Restarting the CC app each and every time the fonts become unavailable is quite time consuming to my workflow.
    Thanks!

    Abhishek,
    Thank you for the reply. Wanted to comment on a few things.
    I reviewed the other post that you've referenced. Nothing unusual jumped out at me as something that I was not aware of. I'm running an older iMac that is in good working condition. 2.4 GHz Intel Core 2 Duo, 24" screen. I know this issue is fleeting, as I stated earlier typically can be corrected with a restart of the CC Desktop application (that I am always running at startup). I have not been able to determine that shutting down Muse corrects the issue. I would, at this time say it doesn't.
    I did open InDesign and see if the fonts in question, Open Sans and Open Sans Condensed, were present and usable. They were. The fonts are shown as being synched in my CC Desktop app window (even if they are not "installed" in Muse). That is expected but it may be a bug in how Muse brings in a font from those that are already synched to your CC account. I don't know enough about how that works to comment.
    And just to complicate matters, Muse seems to be working again, the fonts that is. I brought them back in and they are showing up in all locations (which there are actually three - see screen shots).
    First is primary text menu dropdown (to right of orange "Text").
    Second is if you click orange Text link. Another drop down menu appears.
    And lastly, the Text Panel to right of screen.
    I also wanted to add this extra bit of information, for what it is worth. When the issue arises and you do not get the sub-menu dropdown showing various styles of the font (italics, bold, etc.), one can use click on the missing font if you had used it previously and it is present in the "previously used font" list.
    Cheers!

  • HT4913 i am trying to get my computer and my wifes computer on my itunes match.  i did the add a computer function and it says that this computer is already associated with an apple id...if you use itunes match with your apple id etc for 90 days...please

    i did the add a computer function and it says that this computer is already associated with an apple id...if you use itunes match with your apple id etc for 90 days...please explain.  is this going to screw my wifes account up? 

    If you both have seperate iTunes Store accounts then basically, yes, it is going "screw up" your wife's account.
    iTunes Match is designed as a single-user service which is associated with one and only one iTunes Store account ID. If you have subscribed on your account and want to activate the service on another computer that is already signed in with an account the present account must be signed out and then iTunes signed into your account. This means the other computer will have complete access to your account and will only be able to make purchases on your account. iTM is not designed to be signed in and out at will. If she has apps purchased with her iTunes Store account they will not be able to be updated.

  • ABAP - Function module to get the number of working days between 2 days

    Hi gentlemen,
    I have been asked to produce a report that gives the number of working days between 2 days, based on a calendar.
    I didn't find anything...
    Has any of you already written a function module to get this ?
    A great thanks in advance.
    Jacques Lagrif

    Hi ,
    you can try this ,
    when you require the number of working days between D1 and D2
    Total No of Days will be
    D2 - D1
    No of holidays between D1 and D2 , use the FM HOLIDAY_GET
    Pass the From date , to date , and the factory calendar to get the of Holidays
    Total no of days - Number of Holidays will your Working days
    Regards,
    Sathya

  • Function module for getting teh last working day of a month.

    Hi GURUS,
    this is criteria,please help me 
    if V_T001B- FRYE1 < month entered in selection screen
              Then throw the error message
                Else
    Find the previous period and its last working day from the function module
          (i..e Assume entered date as June 2 2009 then
                   Period 6 -1 = 5.
         Pass the month 05 to function module then
                   Find last working day.
                   Keep it in a variable (V_LAST_PRD_WRKDAY)
                           Proceed further.
    thanks in advance,
    Rajeev

    Hi Rajeev,
    You can use Function Module LAST_DAY_IN_PERIOD_GET.
    Ex:
          CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
            EXPORTING
              i_gjahr = p_gjahr
              i_periv = lwa_t009b-periv
              i_poper = lwa_t009b-poper
            IMPORTING
              e_date  = s_audat-high.
    Regards,
    Ravi K

  • Add 12 working days to a date

    I have a date, let's say 01.01.2007, and I want to postpone the date by 12 working days.
    "working days" in my case shall mean only monday to friday, not saturday and sunday, and I do not case about public holidays.
    Is there are function module or something like this to do this calculation?

    check this below link
    Factory Calendar
    u can also have a look into these links
    Getting a date based on factory calendar
    Function module to get the no.of working days between START and END dat
    I want to find the No.of working days between the two dates
    i think it is useful for u
    SANTOSH..

  • URGENT: Add Non-working day value to the next working day

    Hello expertz!
    I have a requirement were i need to shift the values of the non-working days to the next working day. The report allready works, showing only the values for the working days, but for example if i have the amount of 100 on 06.12.2009 (saturday) i want that this value is added to the amount of 09.12.2009, which is the next working day.
    Does anybody knows a solution to do this? Is this possible in BEx?
    Please advise if you think this is not possible.
    Thanks for the help.
    Nuno

    Hi Anil,
    I really appreciate your suggestion, but i'm still not getting the point. How to store the value of the non-working day in a variable and then add it where? Can you please clarify?
    Thank you very much for your help.
    Nuno

  • Function  in param, start_date & number , return sums next working day

    Hi Friends,
    I need a funtion which can take in parameters as start_date and number , sum them as new date and return new_start_date as workind day.
    Suppose '15-SEP-2009' + 6 should return 23-SEP-2009 as new date.
    Basically the sum of date and number should return next working day (excluding saturday,sunday).
    e.g '15-SEP-2009' + 6 =21-SEP-2009 , but it includes saturday and sunday , so it should return 23-SEP-2009.
    Thanks
    Niren

    Hi, Niren,
    The first respondent gave a better function for testing for work days (Monday through Friday). If there's a bug with Saturdays, I'm sure that can fixed. Also,that function depends on your NLS settings. If that's an issue for you, that can be fixed, too. The idea that there are 5 work days in any 7 consecutive days will cut down the execution time considerable.
    A function like I suggested would be useful if you had to consider holidays as well as weekends.
    Here's an untested example:
    CREATE OR REPLACE FUNCTION  work_days_away
    (      in_start_date         DATE
    ,      in_day_cnt         NUMBER
    RETURN     DATE
    DETERMINISTIC
    IS
         IF  in_start_date - TRUNC (in_start_date, 'IW') >= 5
         OR  is_holiday (in_start_date)
         THEN
              RETURN  work_days_away ( in_start_date + 1
                               , in_day_cnt
         ELSIF  in_day_cnt >= 1
         THEN
              RETURN  work_days_away ( in_start_date + 1
                               , in_day_cnt    - 1
         ELSE
              RETURN  in_start_date;
         END IF;
    END     work_days_away;This use the date format 'IW', which does not depend on NLS settings, rather than 'D', which does.

  • Function Module for Date/ Time difference in Working Days

    Hi all,
    Are there any function modules which will calculate the difference between a date AND time, but in working days?
    I can use the FIMA_DAYS_BETWEEN_TWO_DATES_2 FM for the dates, but I need to include times in this as well.
    This is for situations where the 'starting date' is a non-working day, and the 'end date' is a working day.  In this situation I need to take all the hours and minutes into account, which happened on the working day.  To give an example -
    Start date:  04.07.2010 (Sunday - Non working day)
    Start time:  21:12:36
    End date:  05.07.2010 (Monday - Working day)
    End time:  04:47:24
    I realise there is a Time option in this function module, but when I test it, it doesn't seem to be returning the desired results (returns 0 for days and time).  I am using '5' as the I_STGMETH and 'GB' as the I_SKALID. 
    I need a calcuation which will return the time, post midnight on the working day - in this example, 4 hours, 47 minutes (seconds are optional!).
    Can anyone help? - can I still use FIMA_DAYS_BETWEEN_TWO_DATES_2 but with different parameters?
    Thanks
    Mischa
    Edited by: Mischa Gulseven on Jul 20, 2010 10:40 AM

    Hi,
    Thanks but this FM does not seem to account for working days.
    For example, if I use:
    DATE1                           04.07.2010  (non working day)
    TIME1                           04:00:00
    DATE2                           05.07.2010   (working day)
    TIME2                           21:00:00
    It will give the following results -
    DATEDIFF                                                      1
    TIMEDIFF                                                     17
    EARLIEST                        1
    I don't want to account for the non-working day so the result I actually want would be to calculate from midnight on 05.07 to 21:00 on 05.07 which should be 21 hours.
    I suspect I probably need to include the STGMETH and the factory calendar somewhere in the FM?
    Does such a FM exist, or could anyone help me with some ABAP for this?
    thanks
    Mischa

  • HR Function Module for Working Days

    Hi gurus,
    Plz help me with a function module to calculate working days for an employee within a given date range.

    Hi Sudipa,
    Try the FM   DATE_CHECK_WORKINGDAY.
    Check this one for sample:
    Function Module which calculates employee's Working days per year
    Regards,
    Chandra Sekhar

  • Function for calculating working days

    Dear Oracle
    Is there any function to calculate no of working days if I pass From date & To date?.
    Thanks
    Christy.

    This would work for normal weekdays, but what about bank holidays?
    They change from country to country, so you need to create a package yourself.
    We got one that looks like the following:
    create or replace
    package body zentr_date_functions as
      function eastern (p_year in number) return date is
        -- Get easter sunday (working from 1900 to 2099)
        -- CKL 02.09.1998 nach c't 18/98
        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 this 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
          -- fixed date bank holidays in lower saxony, Germany
          return 0;
        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
          -- calculation not possible
          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
          -- good friday, easter monday, ascension day, pentecost monday
          return 0;
        end if;
        return 1;
      end is_workday;
      function workdays_between (p_date1 in date, p_date2 in date) return number as
        -- count number of working days between  p_date1 and p_date2 (incl. both)
        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;
    /

  • "add wireless clients" functionality --not working

    I'm hoping someone can help me figure out the Add Wireless Client functionality in the AirPort utility. I can't seem to get it to work, and even Apple support appears to be stumped.
    I have tried using the "add wireless clients" functionality in the Base Station menu of Airport Utility. When the "Wireless Client Setup Assistant" window opens, there are two choices: PIN or First attempt. Neither option seems to work. In fact, if I try to enter a PIN, I am able to enter a series of numbers, but the continue button does not become enabled.
    Is anyone able to get this to work? I called Apple support and they were supposed to get back to me but they as of yet haven't offered a solution.
    I have an airport extreme 802.11n and express configured in a WDS. Everything else is working perfectly.

    James,
    This topic has been previously discussed - the URL to one such thread which may assist you is http://discussions.apple.com/thread.jspa?threadID=855971
    Regards,
    Chris

Maybe you are looking for

  • Cash Management

    Hello All, Would appreciate guidance wrt implementation of Cash Management. We would be using LSMW for update our Master data with the Planning Groups / levels. However, not aware of the Cash Management Implementation Tool and it's associated problem

  • Search not working

    well, not working like Tiger used to I should say. I used to be able to open the Hard Drive as a finder window, I could then type in what I was looking for in the Search window in the upper right hand corner. Leopard seems to work but I just put a fi

  • How to add a new property security question in atg profile?

    Hi All, I want to add a new field in registration.jsp named as Security Questions; it has 3 questions and it should be ordered and cannot contain duplicate values. For this I have created 1) a customUserProfile.xml under /MyModule/config/atg/userprof

  • New iPod to replace existing iPod?

    Just bought a new 5th gen 60GB iPod for my wife. She has been using the older 40GB iPod and has purchased a ton of music from the iPod (judging by my credit card statements, anyway). Is there anything specific that she needs to do to "de-authorize" t

  • JEditorPane and OutOfMemoryError

    Hello, I'm using a JEditorPane to display a set of html pages. I have two main problems, which a general search tells me is quite common. First of all the CSS isn't recognised, so highlighted text is displayed as plain text. But more importantly, I G