cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Karol
Helper II
Helper II

DatePicker restrict weekend days (Saturday & Sunday)

Hello,


In my scenario I want to prevent users from selecting a Saturday or Sunday in datepicker in my "Required by date" column.

 

I defined on OnVisible Screen:

 

If(
    Weekday(
        Today() + 3,
        StartOfWeek.Sunday
    ) = 1,
    Set(
        varDate,
        Today() + 4
    ),
    Weekday(
        Today() + 3,
        StartOfWeek.Sunday
    ) = 7,
    Set(
        varDate,
        Today() + 5
    ),
    Weekday(
        Today() + 3,
        StartOfWeek.Sunday
    ) <> 7 && Weekday(
        Today() + 3,
        StartOfWeek.Sunday
    ) <> 1,
    Set(
        varDate,
        Today() + 3
    )
)

 

 

What should I do now to achieve my plan? I would like to give users an error message, when they click on Saturday and Sunday in DatePicker.

 

Karol_0-1637501533861.png

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
AmDev
Super User
Super User

Hi @Karol 

 

You can achieve this with the following code in your date picker:

 

  • Onselect: Set(varDate, Self.SelectedDate)
  • DefaultDate: If(Weekday(varDate) =1 || Weekday(varDate) =7, Blank(), varDate)
  • InputTextPlaceholder: If(IsBlank(Self.SelectedDate), Text("DD/MM/YYYY"))

 

In terms of your error message, you could set it's visibility to Weekday(varDate) =1 || Weekday(varDate) =7. i.e. it will then disappear when the user selects weekday between 2 and 6.

 

Hope this helps - good luck!

View solution in original post

2 REPLIES 2
AmDev
Super User
Super User

Hi @Karol 

 

You can achieve this with the following code in your date picker:

 

  • Onselect: Set(varDate, Self.SelectedDate)
  • DefaultDate: If(Weekday(varDate) =1 || Weekday(varDate) =7, Blank(), varDate)
  • InputTextPlaceholder: If(IsBlank(Self.SelectedDate), Text("DD/MM/YYYY"))

 

In terms of your error message, you could set it's visibility to Weekday(varDate) =1 || Weekday(varDate) =7. i.e. it will then disappear when the user selects weekday between 2 and 6.

 

Hope this helps - good luck!

I followed your solution but when I select a weekend date, instead of blank it is displaying me the selected date

 

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Top Solution Authors
Top Kudoed Authors
Users online (3,381)