Subtracting/adding Business days

Hi everyone !
I have a calendar question: I have a date, number of days (either business or calendar) and Before/After indicator.
I need to calculate the future/past date depending on business/calendar nn days.
Ideally, I will also read Holidays table to fix the result with Holidays.
Any suggestions ?
CF allows me to know a weekday, add/subtract units from dates, compare dates, but nothing in the direction I mentioned...
Any suggestions will be greatly appreciated !
Gary.

Make it very easy on yourself:  set up a database table with date as the primary-key, then fill it with 200 years' worth of dates.  ("When you run out, dig me up and I'll fix it then ...")  You can put any sort of information you want to in there, such as (for example...) a "business-day number" that's used only to calculate these differences.  It can literally be anything-and-everything you need to know about dates at your place of business.
When you do this, not only are "complicated calculations" eliminated at-a-stroke, but you can very easily change anything at will.  You're simply using an inner-join and ... voila ... the answer is there.
Although setting up a script (in whatever language) to populate the table is a bit tedious, you only need to do it once.  To me, it beats every other approach hands-down.

Similar Messages

  • Adding Business Days to a Date to create New Date

    I am looking to add a formula to auto calculate a new date, but only want to count business Days.
    Currently I am using formula to calculate how many days need to be added:
    //ODD Priority Business Days
    If left ({DEFECT.PRIORITY}, 1)= "1" then 10    
    else  
    If left ({DEFECT.PRIORITY}, 1)= "2" then 20
    else
    If left ({DEFECT.PRIORITY}, 1)= "3" then 50
    else
    If left ({DEFECT.PRIORITY}, 1)= "0" then 10
    Now I need to create a formula to add these numbers to the date field, for conversation purposes, I need to add these business days to my "start date" to equil my "ODD date".
    Example, if my "start date" is 1/1/2009 and it is a Priority 2, then I need to add 20 business days to that, so the "ODD date" would be: 1/29/2009.
    Please help.

    Thank you Garrett Fitzgerald! Please see the modified formula which I meant
    {Startdate}
        + {@BusinessDays}
        - DateDiff("ww", {Startdate}, {Startdate} + {@BusinessDays}, crSaturday)
        - DateDiff("ww", {Startdate}, {Startdate} + {@BusinessDays}, crSunday)
    Regards,
    Raghavendra

  • Adding Business Days to a formula

    All-
    The formula below is adding a certain number of days to a call date based on dialer result code, but I want to be able to exclude Saturdays and Sundays.... And if it's not too much trouble holidays when adding the days.
    My formula is called @Workdate:
    If {DIALER_IVRCALLDETAIL.IVRDISPID}=106 then {DIALER_IVRCALLDETAIL.CALLSTARTDT}+3
    else
    if {DIALER_IVRCALLDETAIL.IVRDISPID}=105 then {DIALER_IVRCALLDETAIL.CALLSTARTDT}+3
    else
    if {DIALER_IVRCALLDETAIL.IVRDISPID}=90 then {DIALER_IVRCALLDETAIL.CALLSTARTDT}+2
    else
    if {DIALER_IVRCALLDETAIL.IVRDISPID}=91 then {DIALER_IVRCALLDETAIL.CALLSTARTDT}+3
    Else
    if {DIALER_IVRCALLDETAIL.IVRDISPID}=92 then {DIALER_IVRCALLDETAIL.CALLSTARTDT}+2
    I would appreciate any help you can offer!
    Thanks!
    James

    Lets name the existing formula like this
    @DateCalculated:
    If {DIALER_IVRCALLDETAIL.IVRDISPID} in [106,105,91] then ({DIALER_IVRCALLDETAIL.CALLSTARTDT}+3
        - DateDiff("ww", {DIALER_IVRCALLDETAIL.CALLSTARTDT}, {DIALER_IVRCALLDETAIL.CALLSTARTDT}+3, crSaturday)
        - DateDiff("ww", {DIALER_IVRCALLDETAIL.CALLSTARTDT}, {DIALER_IVRCALLDETAIL.CALLSTARTDT}+3, crSunday))
    else
    if {DIALER_IVRCALLDETAIL.IVRDISPID} in [90,92] then ({DIALER_IVRCALLDETAIL.CALLSTARTDT}+2
        - DateDiff("ww", {DIALER_IVRCALLDETAIL.CALLSTARTDT}, {DIALER_IVRCALLDETAIL.CALLSTARTDT}+2, crSaturday)
        - DateDiff("ww", {DIALER_IVRCALLDETAIL.CALLSTARTDT}, {DIALER_IVRCALLDETAIL.CALLSTARTDT}+2, crSunday))
    Now create new formula like this
    if weekday(@DateCalculated)=7 then
    (@DateCalculated)+2
    else if weekday(@DateCalculated)=1 then
    (@DateCalculated)+1
    else
    (@DateCalculated)
    place this in the report which gives the expected date.
    Regards,
    Raghavendra

  • Adding Business Days to a Date

    Hi everyone,
    I'm trying to add a certain number of working days to  a date,what I am hoping to get is a date excluding the weekends
    For example:
    If i was to add 12 working days to 01/05/2009 i should get 19/05/2009
    Thank You
    MT

    Mistook 01/05/2009 as Jan 5th and was wondering why your statements contradicted.  I see you mean May 1st.
    Try a formula such as this:
    numbervar i := 1;
    datevar c := date(#05/01/2009#);
    numbervar z := 12;
    datetimevar k := date(0,0,0);
    while i <= z do
    k := dateadd('d',i,c);
    (if dayofweek(k) in [1, 7] then
    (z := z + 1;)
    k := date(0,0,0);
    i := i +1;
    dateadd('d',z,c);
    where 'C' is the starting date and 'Z' is the number of working days.

  • 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

  • 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

  • How to find the last 4th business day of the month (not include weekend)

    Hi,
    I need help how to code the ABAP program to locate the last 4th business day of the month (not include Satuday, Sunday and holidays).
    For example for the last 4th business day in 2008 are:
    1/28/2008,
    2/26/2008
    3/26/2008
    4/25/2008
    5/27/2008
    6/25/2008
    7/28/2008
    8/26/2008
    9/25/2008
    10/28/2008
    11/21/2008
    12/26/2008
    Thank you so much!
    Helen

    Hello Helen
    I would use a two-step approach:
    (1) Set date to the first of day of month (e.g. 20080201 = 01.02.2008)
    (2) Subtract four working days from this date
    If I remember correctly there is a function group BKK available which contains fm's for adding workdays to a given date (search for 'BKKWORKDAY). To subtract a number of working days use a negative number.
    See also: [BKK_GET_MONTH_LASTDAY|reg :BKK_GET_MONTH_LASTDAY;
    Regards
      Uwe

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

  • Service Requests-Business days when year changes

    Hi All,
    I am trying to calculate for how long a SR has been open in business days only.
    I have successfully used Mike Lairson's formula for the last 9 months but it seems it cannot cope with year changes. If the begin data is in 2009 and the end date in 2010, the results are not correct anymore.
    E.G. For an SR that was opened on 12/30/2009 and closed on 01/05/2010 should return 5 business days but it is actually returning 110.
    The syntax that I used so far is:
    (CASE
    /* Convert Sunday to the Business Day Of the Year */
    WHEN DAYOFWEEK("Service Request"."Closed Date and Time") = 1
    THEN (DAYOFYEAR("Service Request"."Closed Date and Time") - WEEK("Service Request"."Closed Date and Time")) -
    (WEEK("Service Request"."Closed Date and Time") - 2)
    /* Convert Saturday to the Business Day Of the Year */
    WHEN DAYOFWEEK("Service Request"."Closed Date and Time") = 7
    THEN (DAYOFYEAR("Service Request"."Closed Date and Time") - WEEK("Service Request"."Closed Date and Time")) -
    (WEEK("Service Request"."Closed Date and Time") - 1)
    /* Convert Mon-Fri to the Business Day Of the Year */
    ELSE (DAYOFYEAR("Service Request"."Closed Date and Time") -
    WEEK("Service Request"."Closed Date and Time")) +
    (2 - WEEK("Service Request"."Closed Date and Time")) END)
    (CASE
    /* Convert Sunday to the Business Day Of the Year */
    WHEN DAYOFWEEK("Service Request"."Opened Date") = 1
    THEN (DAYOFYEAR("Service Request"."Opened Date") -
    WEEK("Service Request"."Opened Date")) -
    (WEEK("Service Request"."Opened Date") - 2)
    /* Convert Saturday to the Business Day Of the Year */
    WHEN DAYOFWEEK("Service Request"."Opened Date") = 7
    THEN (DAYOFYEAR("Service Request"."Opened Date") -
    WEEK("Service Request"."Opened Date")) -
    (WEEK("Service Request"."Opened Date") - 1)
    /* Convert Mon-Fri to the Business Day Of the Year */
    ELSE (DAYOFYEAR("Service Request"."Opened Date") -
    WEEK("Service Request"."Opened Date")) +
    (2 - WEEK("Service Request"."Opened Date"))
    END)
    +
    /* Adjust for Year Change */
    (365 * (YEAR("Service Request"."Closed Date and Time") -
    YEAR("Service Request"."Opened Date")))
    Any ideea or hint would be highly appreciated.
    Thank you.
    Regards,
    Dorin
    Edited by: user805960 on 06.01.2010 07:07

    Hi,
    i used this formula to find out the days it calculates between 31/12/2009 and 01/01/2010, the result it gave was 106 days.
    So i subtracted 106 from 365 days (365-106=259)in the formula, the formula is now giving the correct values.
    I think we have to add the total working days and not the no.of days in a year.
    Please can you all reconfirm the results.
    Thanks
    Neena
    Edited by: NNK on Jan 11, 2010 3:16 PM

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

  • Working/Business Days with TimeStampDiff

    Hi,
    Background: I have an order table with a set of possible statuses. There also exists an audit trail that has a timestamp for when a certain status is set.
    Customer wants to measure between two different statuses - which is no problem with a timestampdiff between the two. However, there is also a need to subtract any day classified as a non-business day that falls between the two dates. What i've created is a table that contains the dates that are non-business days. In SQL, i would do this by doing the timestampdiff, then subtracting the count of days that falls between the two dates in the timestampdiff.
    The problem comes when i try to express this in the business model... I can of course do the timestampdiff, but i cannot seem to find a way to do the count of the days in the exception table. Anyone have an idea of how to solve this?

    The easiest way that i can think of is to have a database function created within the database which would accept the 2 dates as parameters and would return the count. Use EVALUATE to call the database function. Use my blog entry here http://oraclebizint.wordpress.com/2007/09/10/oracle-bi-ee-10133-support-for-native-database-functions-and-aggregates/ which would give you a basic idea of calling the database functions.
    Thanks,
    Venkat
    http://oraclebizint.wordpress.com

  • 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

  • Calculate "Business Days" and account for holidays

    I have played with Date math based on what I have found for documentation, and adding an arbitrary number of days is pretty easy. But what about adding an arbitrary number of business days? I found a web site that talks about "Next business day",
    which could be adapted I am sure, but it only accounts for weekends. I want to calculate the date an arbitrary number of business days from a provided date. So, +3 business days calculated from a Monday should produce the date of the following Thursday,
    and calculated from a Friday should produce the date of the next Wednesday. And calculated from Friday Sept 4, 2015 (Friday before Labor Day) should produce Thursday Sept 10, 2015.
    Given that Windows is very business focused, I wonder if there is some nice hidden .NET functionality to calculate business days based on holidays as well? I know, some offices might give extra days off, four day weekends, etc. But those would be edge case
    enough to be safely ignorable for my purposes. Indeed, even holidays could probably be ignored, but if there is a quick approach I would rather use it. If I would need to code some sort of Exchange calendar scraper or some such, I'll live with just accounting
    for weekends. ;)

    You can pull holiday info from outlook.hol file and do the date math based on it. It won't be 100% reliable though. Not all the holidays listed in calendar are non-business days (not in all countries at least). International support may also present additional
    issues: in some countries it is a common practice to "move" weekend days to fill a single day gap between holidays and weekend (which screws up next business day calc anyway, regardless of holiday info :-). Not to mention all the possible industry-wide
    or company specific policies regarding working days.
    Gleb.

  • Calculate number of Business Days

    I need to calculate number of Business Days in BODS. Lets say I have One source table and One Date Dimension table to identify Business Day and need to calculate the no of working days and load in to FACT table (Like in screenshot below)?
    By adding Query transform, I can calculate no of Days, but how to calculate working days between ORDER_RECEIVED_DATE and ORDER_SHIPPED_DATE.
    SQL: select count(*) from DIM_DATE  where DATE between ORDER_RECEIVED_DATE and ORDER_SHIPPED_DATE and HOLIDAY_FLAG='NO'

    Prashanth Chinta,
    I have simulated this Job in my repository and and below are the steps by step implementation.
    Your Dataflow will look like below. It contains the source and Target table with expected results. Hope this is what you are looking for.
    DIM_DATE table contains all the dates in a year and mark each date either Holiday as 'YES' or 'NO'
    Qry_Total_Ship_Days Query Transform
    Qry_Join Query Transform
    Qry_Filter_Holidays Query Transform
    Qry_Cnt_Holidays Query Transform
    Qry_Cnt_Holidays Query Transform (This is to show the groupby columns)
    Qry_Cal_Ship_Days Query Transform

  • Need to return Business Days

    Post Author: latingntlman
    CA Forum: WebIntelligence Reporting
    I have two date fields:  EstDateofDeparture and  EstDateofArrival.
    My problem is when EstDateofDeparture falls on a Friday then EstDateofArrival shows on a Saturday and we don't deliver on Saturdays.We do have departures on Saturdays but no pickups on Sats and sundays.
    So I need the EstDateofArrival to be the following business day (Monday).Here's an example below:
    EstDateofDeparture:  Friday, Dec 7th, 2007EstDateofArrival:       Saturday, Dec 8th, 2007  (it needs to be Monday, Dec 10th, 2007 -- next business day).
    Example # 2:
    EstDateofDeparture:  Saturday, Dec 8th, 2007EstDateofArrival:       Sunday, Dec 9th, 2007  (it needs to be Monday, Dec 10th, 2007 -- next business day).
    T-SQL has a functionalilty where you could for example add getdate()-1 or getdate()+2.
    But I can't find anything in webi formula editor that shows me how to I can do that.
    Is there a function for this??
    thx,
    John

    Post Author: jsanzone
    CA Forum: WebIntelligence Reporting
    John,
    You will need to use a combination of two functions:
    =If(DayName(&#91;EstDateofDeparture&#93;)="Saturday";RelativeDate(&#91;EstDateofDeparture&#93;;2); if(DayName(&#91;EstDateofDeparture&#93;)="Sunday";RelativeDate(&#91;EstDateofDeparture&#93;;1);   &#91;EstDateofDeparture&#93;))
    Use the DayName() function to determine if it is a Saturday (and if so add two days, else add 1 day for a Sunday), and use the RelativeDate() function when adding days to a date.  If the day is neither Saturday or Sunday then leave the EstDateofDeparture in-tact.

Maybe you are looking for