In this blog, we’ll look at how to disable weekends while using the Power Apps date picker control. In other words, if the user chooses Saturday or Sunday from the Power Apps date picker, they are restricted from choosing those days.

Similarly, if they choose any weekdays, they will receive a notification. The steps below must be taken in order to meet with this requirement:

  • On the Power Apps screen, add a date picker and a button control.

  • Add the following expression to the button’s OnSelect property to create a collection.

Collect(WeekDays, {WeekDays:”2″}, {WeekDays:”3″}, {WeekDays:”4″}, {WeekDays:”5″}, {WeekDays:”6″});

Where WeekDays is the collection header name and TestWeekDays is the collection name.

Next, add the following expression to the Power Apps date picker control’s OnSelect property.

If(Weekday(DatePicker1.SelectedDate) in TestWeekDays, Notify(“You selected a weekday”, NotificationType.Success), Notify(“Donot select weekend”, NotificationType.Error))

where DatePicker1 is the name of the date picker control in Power Apps.

That’s it. Now preview the application, select a weekday from the date picker control, and click the button to build a collection to see the result.

 

In a same way, if we choose the weekend from the date picker control, we can see that it will impose restrictions on us by displaying a warning message.

This is how we can prevent users from choosing weekends from the Power Apps date picker control.