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.

Similar Messages

  • 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

  • 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

  • HT2204 I created two iTunes accounts:  one for business purchases and one for personal.  However, when I try to purchase an iBook on my personal account only the business account information appears, and my business password is requested.  How can I selec

    I created two iTunes accounts:  one for business purchases and one for personal.  However, when I try to purchase an iBook on my personal account only the business account information appears, and my business password is requested.  How can I select a different account depending on the type of purchase I am making?

    You would have to sign out of the store with that AppleID and sign in with the alternate AppleID.
    Settings -> iTunes & App Stores -> tap the Apple ID showing, logout, then login.
    Beware thought that you can only change a device's AppleID association once every 90 days.
    http://support.apple.com/kb/ht4627
    So if you do this, you will not be able to use the other AppleID on that device for 90 days.

  • EXHAUSTED!!! 25 DAYS AND COUNTING FOR INSTALL!

    Well its got to the point where i think ive just about had it with BT im appalled by them now!!!up to now ive been kept well informed as to what's been going on without me having to ring them .Then Last Friday the day that finally i was gonna get my final appointment (the 4th appointment) i was told yet another excuse/reason as to why this wasn't going to happen and that it will take 48 hrs to sort, so tuesday will now be the day i get my appointment, i was then sent a text with a number and to call  if it wasn't sorted by tuesday which is when they were suppose to ring me again with an update but i didn't get the call (the 1ST time)?
    so i called the number i got texted and its the infinity call centre in Dundee well guess what? the problem still persists and that they sent a request but it still hasn't been answered so it could well be another 48 hrs until openreach respond, i asked for a manager to call me back because the person at the call centre was just not bothered atall about my situation and sounded uninterested,well that didn't happen either.
    My MAC code runs out on the 20th that will be a month since i ordered, just over infact!!! i ordered 17th march.And just to add insult to injury my BT account states that the total order was complete on the 7th april(my 3rd appointment date)and they will be taking the 1st month broadband payment off me by DD on the 23rd april. I KNOW ITS HARD TO BELIEVE BUT ITS ALL TRUE!!!
    SO I WARN ANYONE THINKING OF DEALING WITH BT THINK HARD AND LONG???
    days off work,3 engineer appointments,25 days and counting for install,paying for a service i havnt got and uninterested customer services and managers not returning calls.WELCOME TO BT!!!
    WATCHDOG,CISAS,OFFICE OF FAIR TRADING AND THE MAN HIMSELF IAN LIVINGSTON. all getting emails.

    I read through your thread Boostmonkey like you say similar in alot of ways,only i wished id read your thread earlier as i mite have got things done sooner(infact i don't know how i missed it).Ive had some progress today but im not saying anything as im still waitng for some concrete confirmation.
    Good luck with it anyway. let me know how you get on.

  • HT4946 i am administrator for Mac. My husband and i both have separate iPhones with separate contacts. Since i0S 6.1 update these contacts are now shared which we do not want. I have set up separate iCloud email and account for my husband. How do i ensure

    I am administrator for Mac. My husband and i both have separate iPhones with separate contacts. Since i0S 6.1 update these contacts are now shared which we do not want. I have set up separate iCloud email and account for my husband. How do i ensure that i

    You can continue to use the current AppleID for iTunes, but your husband can create a new AppleID to use to create a new iCloud account that will be his own and not overlap with yours.  If you do not have another email address to use for an AppleID, just get a free Gmail account and use that.
    You can have as many AppleIDs as you want (or at least, as many as you have email addresses for).  You can use a separate AppleID for the store, another for iCloud, and even another for iMessage if you wish.
    You will want to keep the current one as the shared one for the store as all your previous purchases are permanently tied to it, and thus you need that AppleID to update or redownload your current purchased content.

  • TS3276 can anyone help on the following please. When I have been away from the office for a few days and check for emails it only supplies the most recent 100 emails and the ones before that are never received. thanks

    can anyone help on the following please. When I have been away from the office for a few days and check for emails it only supplies the most recent 100 emails and the ones before that are never received. thanks

    Does your server have a limit?

  • Any business Object and Events for CJ01?

    hello friends,
    can any one of u tell me the Business Object and Event for the transaction CJ01?
    Could you please let me know is it  business object (BUS2054) is right one. If it is right one please let me know the Event for CJ01?
    Thanks,
    Sridhar

    Hi Sridhar.
    You want to know if there is triggered an event when you create a project.
    Try the following:
    Activate event trace with SWELS.
    Create a project with CJ01.
    Check transaction SWEL to display trace event.
    Regards
    JCD

  • How to get the data for last 3rd business day and also include saturday and sunday if its a wednesday?

    Hi All,
    I have a simple query which is below:-
    Declare @reportdate date
    set @reportdate= (DATEADD(dd,-5,getdate()))
    select * from dbo.Table
    where date IN (@reportdate)
    I need this query to pull the data for the last 3rd business day .So lets say today is monday then i need the data for last week wednesday which is 3 business days back from monday, if today is a tuesday it would be for last thursday ( as 3 business days for
    tuesday would be thursday). But if today is wednesday then i need to be last 3rd business day which is last friday and i also need to get the data for saturday and sunday.
    Can someone please help me how cani change my filter to do this?
    Please let me know if i am still unclear.
    Thanks

    Hi SqlDev12,
    Based on my understanding on your requirement, you can reference the below sample.
    CREATE TABLE BusinessTable
    Bdate DATE,
    Wd VARCHAR(10)
    ;WITH Cte(DT,WD) AS
    SELECT CAST('20150401' AS DATE),DATENAME(WEEKDAY,CAST('20150401' AS DATE))
    UNION ALL
    SELECT DATEADD(DAY,1,DT),DATENAME(WEEKDAY,DATEADD(DAY,1,DT)) FROM Cte
    WHERE DT<GETDATE()
    INSERT INTO BusinessTable SELECT * FROM Cte
    SELECT * FROM BusinessTable
    SET DATEFIRST 7 -- Set Sunday as the first day of a week
    DECLARE @givenDay DATE ='20150415' --Wednesday
    SELECT * FROM BusinessTable
    WHERE Bdate BETWEEN
    --For Monday and Sunday, select last wednesday
    (CASE WHEN DATEPART(WEEKDAY,@givenDay) IN(1,2) THEN DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay)-1,0))
    --For Tuesday and Wednesday, last week's Thursday and Friday
    WHEN DATEPART(WEEKDAY,@givenDay) IN(3,4) THEN DATEADD(DAY,-5,@givenDay)
    --For Thursday and Friday, current week's Monday and Tuesday
    WHEN DATEPART(WEEKDAY,@givenDay) IN(5,6) THEN DATEADD(DAY,-3,@givenDay)
    --For Saturday, current week's Wednesday
    ELSE DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay),0)) END)
    AND
    (CASE WHEN DATEPART(WEEKDAY,@givenDay) IN(1,2) THEN DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay)-1,0))
    WHEN DATEPART(WEEKDAY,@givenDay) IN(3) THEN DATEADD(DAY,-5,@givenDay)
    WHEN DATEPART(WEEKDAY,@givenDay) IN(4) THEN DATEADD(DAY,-3,@givenDay)
    WHEN DATEPART(WEEKDAY,@givenDay) IN(5,6) THEN DATEADD(DAY,-3,@givenDay)
    ELSE DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay),0)) END)
    DROP TABLE BusinessTable
    If you have any feedback on our support, you can click
    here.
    Eric Zhang
    TechNet Community Support

  • Calculate Business day

    Hi,
    Iam working on a logic to calculate the posting date in XI. I have used graphical mapping in the scenario.
    The logic is to claculate the 3rd business date of the month. You need to look at the calendar and exclude Saturdays, Sundays and Holidays.
    For example if we take February 2008 the 3rd business day is 5th Feb 08 as 02/Feb and 03/Feb are saturday and sundays.
    If monday(04/Feb) was a holiday then the 3rd business day will be 6th Feb.
    Can you give this logic in XI graphical mapping.
    Best Regards
    Suresh

    Hi Ram,
    Thanks for the immediate reply. The XI scenario is File to IDOC. But the scenario is already developed using graphical mapping and I just need to change the posting date logic in it. I believe the holidays are maintained in SAP tables. Is there a way to get the holidays list from SAP using User defined functions in XI.
    Best Regards
    Suresh

  • How to Schedule a Report to Run on a Specific Business Day and Not on the Weekend

    Hi,
    Is there a way to schedule a Webi report to run on a specific Business Day? For example, if I wanted a report to run on the 3rd day of every month, but when the 3rd day for a particular month landed on a Saturday or Sunday, then Monday would automatically be chosen instead. Is that possible?
    Thanks,
    Michael

    Hi Michael,
    You can do that by selecting the calendar option while scheduling the report and manually selecting the 3rd day of every month and when the 3rd day for a particular month landed on a Saturday or Sunday, then select the next Monday.
    I dont see any option available for this scenario directly in BO.
    Regards
    Sri Harsha

  • Uni days premium account for 4,99€

    Hey,
    If you are studying at a German University, you can register at "unidays" and get the premium account for 4,99 €.
    Since I already have a premium account I wonder if the 50 % off can be added to my account. I already followed the steps on the uni days website but my account still says that I am currently paying 9,99€.
    Can anyone help me here?
    Thank you
    Greetings, julius

    Hey
    Thanks for posting in the community and welcome on board :)
    Could you try re-adding the details for me? We've performed a little maintenance this end.
    If there's still troubles, get in touch with us on the contact form below:
    https://www.spotify.com/about-us/contact/contact-spotify-support/
    Make sure to reply back to the automated response and it'll make sure one of the correct team get your email correctly!
    Hope that helps.

  • Calculate business day between two dates

    Hi Guys
    I need the count of business days between two  dates
    Date1, Date2 i need the count only business day (exclude sartuday&sunday)
    If date1 is null or nothing i need to pass 0
    If date2 is null or nothing i need to pass 0
    help on this

    Hi,
    To achive this within SSRS, go to the report code window and add the below
    Function getBusinessDaysCount(ByVal tFrom As Date, ByVal tTo As Date) As Integer
    Dim tCount As Integer
    Dim tProcessDate As Date = tFrom
    For x as Integer= 1 To DateDiff(DateInterval.Day, tFrom, tTo) + 1
    If Not (tProcessDate.DayOfWeek = DayOfWeek.Saturday Or tProcessDate.DayOfWeek = DayOfWeek.Sunday) Then
    tCount = tCount + 1
    End If
    tProcessDate = DateAdd(DateInterval.Day, 1, tProcessDate)
    Next
    Return tCount
    End Function
    In the textbox where you need to display the value, add the below expression
    =Code.getBusinessDaysCount(parameters!StartDate.Value,parameters!EndDate.Value)
    It is assumed the you want to pass the two days from parameters named Startdate and EndDate. If not, modify the expression with required values.
    Regards
    Please click "Mark as Answer" if this resolves your problem or "Vote as Helpful" if you find it helpful. BH

  • Validation for Business place and section for With holding tax

    Dear friends
    I defined validation for MIRO with respect to Business place and Section code to make mandatory, it is working fine.
    But in case of F-47 / F-48 and FB60 I defined validation but not working.
    Please help me in this regard
    Thanks in advance
    Kiran A

    Hi
    Your query is not clear? What is the prerequisite and check you have defined in validation rule? I doubt that in prerequisite you have defined the T Code MIRO. Pls check and assing the other T Codes also if that is the case.
    Regards
    Sanil K Bhandari

  • Setting up Apple ID and Accounts for Kids

    I'd like to setup 2 accounts for my kids - but don't want to setup separate e-mail accounts - I'd like to like them to my e-mail account.
    Can this be done - i.e. link multiple apple IDs to one mail?
    Or can I setup an itunes account with a voucher without the need for an e-mail address?
    If not, it's not much hassle to setup the e-mail and only give em the password to the itunes account and not the mail address.

    This is most unlikely, since if any charges go void apple will most likely be responsible for this and will have to pay out around $10 for every dollar charged (and not paid off) and you must be of age 13 to sign up for an apple ID. Hope I helped.

Maybe you are looking for