In this Power Apps Tutorial, we will see how to handle the error “Can’t convert this data type. Power Apps can’t convert this Date to a Boolean” within the Power Apps date picker control.
We recently experienced the above-mentioned error while working on a requirement using the Power Apps date picker control within a canvas app.
According to the requirement, the power apps date picker control will prevent the user from selecting weekends (i.e., Saturday and Sunday). If the user chooses a weekend from the date picker, it will display an error message or disable the control; if the user chooses a weekday, it will display a success message.
To begin working with this scenario, I used a solution from the Power Apps forum. Maybe it works for someone else, but it didn’t work for me. To obtain the solution, please visit the mentioned link: Display only weekdays in DatePicker.
Error: Can’t convert this data type. Power Apps can’t convert this Date to a Boolean
The below screenshot represents the error message that appears in Power Apps while using the Date Picker control.
ERROR MESSAGE:
Can’t convert this data type. Power Apps can’t convert this Date to a Boolean.
Now we will discuss how and when this error comes in Power Apps Date Picker Control.
Recently, I have created an app where I need to restrict the user from selecting weekends (i.e., Saturday and Sunday). At the same time I found the above solution and below are the steps:
- On the Power Apps screen, I have added a date picker control as well as a button control to submit the selected date from the date picker control.
- On the button’s OnSelect property, I have inserted the below expression to create a collection.
OnSelect = Collect(Collweekend, Weekday(BusinessDay_DatePicker.SelectedDate) = 1 Or 7)
Where,
- CollWeekend: Name of the collection
- Weekday(): This function returns a Date/Time value’s weekday. The result by default ranges from 1 (Sunday) to 7 (Saturday).
- BusinessDay_DatePicker: Name of the Power Apps date picker control
- Then, I added the below expression on the button’s DisplayMode to disable the button control on selecting the weekends from the Power Apps Date Picker control. But instead of the solution, we got the error shown below:
DisplayMode = If(BusinessDay_DatePicker.SelectedDate in Collweekend, DisplayMode.Disabled,Edit)
Also Read: How to Patch Power Apps Date Picker
Solved: Can’t convert this data type. Power Apps can’t convert this Date to a Boolean
Alternatively, I have resolved this issue by using another solution that you can refer to by using the instructions below.
As we already have a date picker control and button control, we don’t need to add them again. The remaining steps to correct the error are as follows:
- On the button’s OnSelect property, insert the below expression to create a collection.
OnSelect =Collect(Collweekend, {WeekDays:"2"}, {WeekDays:"3"}, {WeekDays:"4"}, {WeekDays:"5"}, {WeekDays:"6"});
Where,
- Collweekend is the name of the collection that we have created
- WeekDays is the name of the collection header.
- 2,3,4,5,6 are the weekday numbers representing the weekdays i.e., Monday, Tuesday, Wednesday, Thursday, and Friday respectively.
- Next, insert the below expression on the OnSelect property of the Power Apps date picker control.
OnSelect = If(Weekday(BusinessDay_DatePicker.SelectedDate) in Collweekend, Notify("You selected a weekday", NotificationType.Success), Notify("Donot select weekend", NotificationType.Error))
Where,
BusinessDay_DatePicker = Name of the Power Apps date picker control
According to the above expression, if a user selects any weekday from Monday to Friday from the date picker, a successful notification will appear; otherwise, the user will be prevented from selecting weekends by displaying an error message.
- That’s it. Now save and preview the app, then click on the button (Create Collection) 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.
In this Power Apps Tutorial, we discussed how to resolve this issue “Can’t convert this data type. Power Apps can’t convert this Date to a Boolean.” while working with the Power Apps date picker control.
Also covered is how to prevent users from selecting weekends from the Power Apps date picker control.
Furthermore, you may like some more Power Apps tutorials:
- Power Apps Filter With Date Picker
- How To Set Default Date in Power Apps Date Picker
- How to Reset Power Apps Date Picker
- Power Apps Checkbox control within Gallery
- How to use Power Apps Check Box Control
- How To Set Default Value in Power Apps List Box Control
- Power Apps Listbox items from SharePoint list
- How to use Power Apps List box control?
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.