Freigeben über


Validate if the date selected using date picker control, as weekday or weekend, in SharePoint Infopath form

Hello, Did you try validating the date selected is a weekday or weekend on an infopath form. This post will help how you can validate the selected date as weekday or weekend. If its weekend validate and show appropriate message to user to correct the entry. 

 

Here is the solution how you can achieve it in few simple steps:

[Note: This will works for office 365 sharepoint sites as well]

1. Select date picker on Infopath form designer name it ( From Date in this case).

 

2. From ribbon click on manage rule

 

 

 

 

 

 

3. Select a new Validation rule and name it as you prefer. In my case its Weekend RULE

 

 

 

4. In the condition, you need to check for the date entered is weekend. To do that first, we need find the weekdays in such a way that sunday =1 through saturday = 7

XPath function to find the week of the day

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

In here, You need change  ./my:From_x0020_Date as your field name appropriately, ex; if your field name is input date it will be  ./my:input_x0020_date

(Note: This formula is found in several online blogs)

This formula brings output value between 1 to 7.

1 meaning Sunday and 7 is Saturday.

 

5. Now, we need to check if the date selected from the date picker(From date) field is weekday or not and show appropriate validation to user.

To do that perform below: Edit the Condition, check for date field as not blank

And, next select the expression from dropdown and 

Now, enter the XPath condition given above and check if its equal to 1(for SUNDAY) OR 7(for SATURDAY)

 And last set screen message to users

 

Output

 

Hope this is useful. 

 

Share your thoughts if its helpful to you in anyway. Thanks for visiting..

Raghav

Comments

  • Anonymous
    November 20, 2014
    Hello Sir, Thanks for your post.. I'm using InfoPath Designer 2013...i followe all the Step mention above......Bt im nt getting output.....Please help me....i have to complete my project....Reply as soon as possible.... pankajambartani@gmail.com