User in a work setting often needs to exclude weekends and only account for business days when entering information. This post will demonstrate how to design a SharePoint form that determines whether a business day was selected from the date picker.
- Have your Data Field ready
You’ll need 3 data fields. 1st to capture the date; 2nd to find out the day of the selected date; 3rd to determine whether that day is a business day. For this post, we’ll use these Data Fields as reference:- MyDate (Date field) = to capture user input
- CalculatedDay (Whole Number field) = to determine the day
- IsBusinessDay (True/False field) = to determine business day
- Click fx in Default Value of the CalculatedDay field
- Click “Edit XPath (Advanced)”
- Paste the following formula (NOTE: I didn’t come up with this. I found it, but lost the reference. If you know of the person who BRILLIANTLY came up with this, please let me know so I can give the proper respect/kudos/credit.):
(number(substring(../my:MyDate, 9, 2)) + number(number(substring(../my:MyDate, 1, 4)) - floor((14 - number(substring(../my:MyDate, 6, 2))) div 12)) + floor(number(number(substring(../my:MyDate, 1, 4)) - floor((14 - number(substring(../my:MyDate, 6, 2))) div 12)) div 4) - floor(number(number(substring(../my:MyDate, 1, 4)) - floor((14 - number(substring(../my:MyDate, 6, 2))) div 12)) div 100) + floor(number(number(substring(../my:MyDate, 1, 4)) - floor((14 - number(substring(../my:MyDate, 6, 2))) div 12)) div 400) + floor(31 * number(number(substring(../my:MyDate, 6, 2)) + 12 * floor((14 - number(substring(../my:MyDate, 6, 2))) div 12) - 2) div 12)) mod 7
- Replace all of my data source with yours by doing the following:
- Highlight the first reference of “../my:MyDate”
- Click “Insert Field or Group”
- Select your date field then click OK
- Repeat the steps and replace all references of “../my:MyDate”
- Click “Verify Formula” and you want to see a no error confirmation like shown below
- When a date is selected by the user, this field will now generate a number from 0 to 6 that corresponds to a particular day (0 = Sunday; 1 = Monday; 2 = Tuesday; … 6=Saturday)
- Select CalculatedDay field
- Click Manage Rules on the ribbon
- Add a new action “Mark as Business Day”
- Create the following Condition:
- CalculatedDay “is greater than or equal to” 1
AND
CalculatedDay “is less than or equal to” 5 - Add the following action
- “Set a field’s value”
- Select field of “IsBusinessDay”
- Assign the value of true
- Click fx
- Insert Function
- Find and select “true”
- Click OK
- “Set a field’s value”
- Click OK
- Select CalculatedDay field
- Click Manage Rules on the ribbon
- Copy the Business Day rule from above and change the action name to “Mark as Weekend”
- Update the Condition to:
- CalculatedDay “is equal to” 0
OR
CalculatedDay “is equal to” 6 - Update the action to:
- Field = “IsBusinessDay”
- Assign the value of false
- Click fx
- Insert Function
- Find and select “false”
- Click OK
- Click OK
- The CalculateDay field rules should look as follow
And there you have it.
You now have a Boolean identifier in the IsBusinessDay field that you can use to validate the date input. One potential scenario is to disable a submit button if the user were to select a non-business-day. Another, shown in screenshot below, is to leverage an error message and a validation flag on the Date field, should a weekend date is selected by the user. Here’s the form in Preview mode:
