SharePoint 2013 Calculate business day from InfoPath date picker or Get Day from selected date in Date picker in InfoPath 2013

This InfoPath 2013 SharePoint tutorial explains, how we can get a business day from InfoPath date picker based on the selected date in SharePoint 2013/2016/Online. Also, we can get Day from selected InfoPath date picker selected date. Let us say I have a Date picker in my InfoPath form, on a selection of a date I want to see what is the day name.

Approach:
Here in this example, I have taken 3 fields:
1- Date Of Birth: This is a date picker in InfoPath 2013 form. Here I have set the default date to now(). If you will try to set the default date by using today() function, you may get an error saying “only date or date and time allowed”. Check out this article to resolve the error.

2- Date Code: This is Number field in InfoPath 2013 form.

3- Day Name: This is a single line of text field in InfoPath 2013 form.

Now right click on the Date Code field and then click on fx button in the default value and write the below formula in it. And make sure to check the check box “Refresh value when formula is recalculated”.

(number(substring(../my:DateOfBirth, 9, 2)) + number(number(substring(../my:DateOfBirth, 1, 4)) – floor((14 – number(substring(../my:DateOfBirth, 6, 2))) div 12)) + floor(number(number(substring(../my:DateOfBirth, 1, 4)) – floor((14 – number(substring(../my:DateOfBirth, 6, 2))) div 12)) div 4) – floor(number(number(substring(../my:DateOfBirth, 1, 4)) – floor((14 – number(substring(../my:DateOfBirth, 6, 2))) div 12)) div 100) + floor(number(number(substring(../my:DateOfBirth, 1, 4)) – floor((14 – number(substring(../my:DateOfBirth, 6, 2))) div 12)) div 400) + floor(31 * number(number(substring(../my:DateOfBirth, 6, 2)) + 12 * floor((14 – number(substring(../my:DateOfBirth, 6, 2))) div 12) – 2) div 12)) mod 7

Here ../my:DateOfBirth is my date picker. You can change according to your field.

So it should look like below:

SharePoint 2013 Calculate business day from InfoPath date picker or Get Day from selected date in Date picker in InfoPath 2013
SharePoint 2013 infopath calculate business days

The above formula will return an integer value which is range between 0 to 6, where:

  • 0 represent Sunday
  • 1 represent Monday
  • 2 represent Tuesday
  • 3 represent Wednesday
  • 4 represent Thursday
  • 5 represent Friday
  • 6 represent Saturday

So if that returns 0 or 6 then that is not a business working day.

Now in the Date Code field change, I wrote few rules to get the day in the Day Name field. So the rule is like if Day Code =6 then Populate Saturday in the Day Name field. see the fig below:

SharePoint 2013 Calculate business day from InfoPath date picker or Get Day from selected date in Date picker in InfoPath 2013
SharePoint 2013 Calculate business day from InfoPath date picker or Get Day from selected date in Date picker in InfoPath 2013

Now Deploy the InfoPath 2013 form to SharePoint Online or SharePoint 2013/2016 and when you will open the form it will appear like below:

SharePoint 2013 Calculate business day from InfoPath date picker
SharePoint 2013 Calculate business day from InfoPath date picker
Now suppose you will change the date then it will appear like below:
SharePoint 2016 Calculate business day from InfoPath date picker
SharePoint 2016 Calculate business day from InfoPath date picker
Hope this InfoPath 2013 SharePoint tutorial explains how to calculate business day from InfoPath date picker or Get Day from a selected date in Date picker in InfoPath 2013 in SharePoint 2013/2016 or SharePoint Online.
Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

  • Thank you for this article it was extremely helpful! By being able to associate a day of the week to a number I was able to apply a validation rule to the date picker which would apply to me having the day of the week I wanted selected!

  • >