This Power Apps tutorial will go over a few examples of how to disable date picker control in Power Apps based on certain conditions.
I had a requirement to disable Power apps date Picker control while working with the Power Apps canvas app.
Also, we will discuss how to disable the Power Apps date picker control with the below things.
- How to disable the future dates within the Power Apps date picker
- How to disable past days’ Power Apps date picker control?
- Power Apps date picker disables weekends
- How to disable Sunday in Power Apps date picker
Power Apps date picker disables future dates
In Power Apps, there is currently no way to prevent users from selecting future dates using the PowerApps date picker control’s properties or disabling the future dates within the control. But we can achieve this another way.
That means when the user selects a future date from the Power Apps date picker control, it will restrict the user and give a warning message. To achieve this requirement, the following steps are:
- On the Power Apps screen, add a date picker control.
- Insert the below expression in the BorderColor of the date picker control.
BorderColor = If(JoinDate_DatePicker.SelectedDate > Today(), Color.Red, RGBA(101, 128, 187, 1))
Where JoinDate_DatePicker is the name of the Power Apps date picker control.
- Next, insert a label control into the screen and place it under the date picker.
- Insert the below warning text on the label’s Text property.
Text = "Make sure not to select any future date"
- Similarly, insert the below expression on the label’s Visible and Color properties respectively.
Visible = JoinDate_DatePicker.SelectedDate > Today()
Color = Color.Red
Let’s test the app by selecting a future date from the current one. (ex- 11/11/2022). As we can see, it prevents the user from selecting a future date. Also, it will not display the error message if the user selects past dates.
This is how to disable the future dates in the Power Apps date picker.
Read How to Patch Power Apps Date Picker
How to disable past days’ Power Apps date picker control?
Similarly, in this section, we will see how to disable the past days while working with the Power Apps date picker control. That means if the user selects a past date from the Power Apps date picker, it will restrict them not to select the past days.
To work with this scenario, the following steps are:
- Add a date picker control to the Power Apps screen.
- Insert the below expression on the OnSelect property of the date picker control.
OnSelect = If(AppointmentDate_DatePicker.SelectedDate<Today(), Notify("The appointment date cannot be before Today. It should be a future date", Error))
Where AppointmentDate_DatePicker is the name of the Power Apps date picker control
Let’s preview it and select a date that is less than the current date from the Power Apps date picker control. We can see, it will restrict us by display notifying an error message.
This is how to disable past dates from the date picker in the Power Apps.
Power Apps date picker disable weekends
Here, we will see how to disable the weekends i.e., Saturday and Sunday within the Power Apps date picker control.
That means when the user selects any weekends it will restrict them not to select weekends. Similarly, it will notify them if they select any weekdays. To work with this requirement, the following steps are:
- Add a date picker and button control on the Power Apps screen.
- On the button’s OnSelect property, insert the below expression to create a collection.
OnSelect = Collect(ColWeekDays, {WeekDays:"2"}, {WeekDays:"3"}, {WeekDays:"4"}, {WeekDays:"5"}, {WeekDays:"6"});
Where ColWeekDays is the name of the collection and WeekDays is the name of the collection header.
- Next, insert the below expression on the OnSelect property of the Power Apps date picker control.
OnSelect = If(Weekday(BusinessDay_DatePicker.SelectedDate) in ColWeekDays, Notify("You selected a weekday", NotificationType.Success), Notify("Donot select weekend", NotificationType.Error))
Where BusinessDay_DatePicker is the name of the Power Apps date picker control.
That’s it. Now preview the app, then click on the button to create a collection, and select a weekday from the date picker control to see the result.
Similarly, select a weekend from the date picker control and we can see it will restrict us by displaying a warning message.
This is how we can restrict the user from selecting the weekends from the Power Apps date picker control.
Read Can’t convert this data type. Power Apps can’t convert this Date to a Boolean
How to disable Sunday in Power Apps date picker
Here, we will see how to disable Sunday Power Apps date picker control. That means it will prevent the user while selecting a Sunday from the Power Apps date picker control.
To work with this requirement, the following steps are:
- On the Power Apps screen, add a date picker control.
- Insert the below expression on the OnChange property of the date picker control to prevent selecting a Sunday.
OnChange = If(Weekday(DatePicker2.SelectedDate, StartOfWeek.Sunday) = 1, Notify("You have selected Sunday", NotificationType.Information), Notify("You have selected working day", NotificationType.Warning))
That’s it! Preview the app and let’s select a day from the date picker control and see the result will come shown below: (Ex- 11/11/2022)
As the above-mentioned day is not a Sunday, so the result came like the above. Similarly, let’s select another date of a Sunday(ex- 11/20/2022).
This is how to disable Sunday in Power Apps Date picker control.
Conclusion
From this Power Apps Tutorial, we learned how to disable the Power Apps date picker control based on the following criteria.
- Power Apps date picker disables future days
- Power Apps date picker disables past days
- Power Apps date picker disables weekends
- Power Apps date picker disables Sunday
You may like the following Power Apps tutorials:
- How To Set Default Date in Power Apps Date Picker
- Power Apps Filter With Date Picker
- How to Reset Power Apps Date Picker
- Power Apps Checkbox control within Gallery
- Power Apps Listbox items from SharePoint list
- How to use Power Apps List box control?
- Power Apps combo box filter
- How to copy Power Apps Data Card value to another
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.