RSS Feed Is this your first time here? Get regular updates

Working Days, Weekdays and Holidays in SharePoint Calculated Columns

Date:November 21st, 2008 Author:Ryan Tags: , , ,
Category: Calculated Columns, SharePoint Ideas, SharePoint Reminder, SharePoint webparts Comments:18 ;

AcmeCorp aim to reply to customer complaints within 3 working days. They plan to use SharePoint Reminder webpart to alert managers when these targets are not being met.

We have a list with the following information

ID Title Date Received Reply Due Reply Sent
1 Order hasn’t arrived Friday 7/Nov/08 Wed 12/Nov/08
2 Order missing items Monday 10/Nov/08 Thursday 11/Nov/08

Once we have this table we could make a View with a filter to only show records that don’t yet have a Reply Sent date (i.e. they have not been dealt with) and then configure a Reminder web part to watch this view and send out emails when the Reply Due date is overdue.

If we didn’t care about working days we could set Reply Due to be a calculated column with a formula of

=[Date Received]+3

The question is – how do we work out the Reply Due date being 3 working days from the received date? (In AcmeCorps case a working week is Monday through Friday)

One of the calculated column functions you can use in SharePoint is Weekday which returns 1 for Sunday, 2 for Monday and through to 7 for Saturday.

So from here we can work out if the day is

Received Weekday Days to add Reply Due
Sunday 1 +4 Thursday
Monday 2 +3 Thursday
Tuesday 3 +3 Friday
Wednesday 4 +5 Monday
Thursday 5 +5 Tuesday
Friday 6 +5 Wednesday
Saturday 7 +5 Thursday

Or writing this another way

Weekday > 3 then +5
Weekday = 2 or 3 then +3
Weekday = 1 then +4

or yet another way

if weekday > 3
   add 5
else if weekday > 1
   add 3
else
   add 4

The final ninja move we need is the IF statement

=IF(some expression, do this if true, do this if false)

and these can be nested and combined with AND/OR or even nested with other IF’s – see the documentation.

We can put this into a formula for SharePoint calculated columns like this

=IF(Weekday([Date Received])>3, [Date Received]+5,
IF(Weekday([Date Received])>1,[Date Received]+3,
[Date Received]+4))

Be very careful when entering this sort of formula, if you get the field names wrong or put a space or a bracket in the wrong place then you will see an error.

You can use the above method if your due date is 4,6,7,8,9 etc days on, just adjust the number of days you add as appropriate.

If your due dates are always a multiple of 5 (e.g. 5,10,15) working days then your job is easier as you will always have 2 weekend days involved so you can just add 7,14,21 etc using =[Field]+7

(FREE BONUS! This also works in Excel, remember to change the Date Received to the column/row reference and don’t use square brackets [] and also format the column as a Date)

But what about holidays?

Ahhh, that’s the problem with this method and there is no easy solution without some complex custom workflow code.

One thing that may work for your circumstance is to add a Reply Due column, set it to Date Time type and set the default value to a Calculated Value with the following formula

=IF(WEEKDAY(Today)>3,Today+5,IF(WEEKDAY(Today)>1,Today+3,Today+4))

This will set the Due Date as 3 working days from when the record was entered but it could be overridden manually if there are holiday days between Today and the due date.

Related posts:

  1. The Truth about using [Today] in SharePoint Calculated Columns This post offers workaround for using values like [Today] and...
  2. SharePoint Calculated columns – Adding hours onto a date field A customer recently contacted me with an interesting question....
  3. Using [Today] in SharePoint calculated default values You can't use Today in SharePoint calculated columns but you...
  4. Tip – Showing multiple columns in SharePoint Planner Webpart This post shows how to show data from more than...
  5. SharePoint Reminder Webpart – Setting a variable Due In or Overdue By time This post gives 3 different methods for setting a variable...

Tags: , , ,

Did you enjoy this post? Get the next one by RSS or by email

Share:

18 Responses to “Working Days, Weekdays and Holidays in SharePoint Calculated Columns”

  1. rahulan says:

    thank you very much. solves a few problems.

  2. rgould says:

    Hi, is there anyway to incoroprate the working day into this, and to add hours rather than days?

  3. Ryan says:

    rgould – I am assuming you mean the scenario of “Reply needed in 3 working hours” so if something came in at 4pm Monday then it would be due (9 to 5 working day) by 11am Tuesday?

  4. Mariel says:

    How would the calculated columns work to take the days between [date 1] and [date 2] and exclude the weekends? I’m trying to get the workday duration between the start date and the end date.

  5. Ryan says:

    Mariel – Good question.

    I’ve spent quite some time looking into this an unless you can make some assumptions such as Date1 and Date2 always finish on the same weekday then its just not feasable as far as I can see.

    Excel has the NETWORKDAYS function and at a push you can make this work using DateDiff (NOTE the two f’s!) – but SharePoint has neither.

    You could possibly do this using XSL functions similar to this, but I will have to leave this for others!

    http://sharepointapplied.wordpress.com/2009/04/23/useless-calculated-column-today-trick-xsl-today-to-the-rescue/

  6. Pete says:

    Hi Ryan, I’ve got an issue where I need to calculate the days taken to complete a task and I used this formula:

    =IF([Actual Date Completed]=0,”NA”,TEXT([Actual Date Completed]-[Start Date],”d:h:mm”))

    The formula works almost perfectly….

    My question is, how do I OMIT weekends if the project runs over consecutive weeks?

    Also, can I OMIT times as well? I.e. We work from 8:30am-5:00pm Mon-Fri so there is no need to have times outside these enter the calculation. It’s very important that the amount of time is as accurate as possible.

    I appreciate your help here!

  7. Chris says:

    @Pete, Did you get your answer? It’s a very valid point and I’m facing the same problem!

  8. Triston says:

    I am also interested in working with hours.

    When a calendar event is being created, I want the end date/time to automatically populate to 1.5 hours after the start date/time. Seems simple, but haven’t found a formula for this yet.

    Thanks.

  9. Ryan says:

    @Pete & @Chris – I think you are pushing the boundaries of what SharePoint formulas can do.

    Depending on your need you could do the calculation client side using JavaScript :-

    http://pathtosharepoint.wordpress.com/2008/08/25/a-countdown-for-tasks-lists/

  10. [...] asked in another post: “When a calendar event is being created, I want the end date/time to automatically populate [...]

  11. Dave says:

    What about when you have due dates that are 30, 45, or even 60 days out? How do you address the multiple weekends?

  12. Dave says:

    Nevermind figured it out !!!!!

  13. [...] I do that? Well I found a great post Working Days, Weekdays and Holidays in SharePoint Calculated Columns that describes how the WEEKDAY formula works and understood that I just needed to change my [...]

  14. Damo says:

    To work with hours simple divide by 24.
    Eg. = [MyDatetimeColumn] + 3/24

    Adds 3 hours.

  15. Ryan says:

    @Damo – I’ve written about that here – SharePoint Calculated Columns – adding hours to a date field

  16. Todd Wilder says:

    I blogged about calculating total hours, holiday hours working hours and non-working hours here:

    http://www.spindepth.com/2010/06/calculating-business-hours-in.html

    Basically its too difficult to do all this with calculated columns, so I have a content editor web part that has a button that uses javascript to update a list’s calculations, kind of like a refresh button.

Leave a Reply