[Solved]Can’t convert this data type. Power Apps can’t convert this Date to a Boolean

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.
Can't convert this data type. Power Apps can't convert this Date to a Boolean
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,

  1. CollWeekend: Name of the collection
  2. Weekday(): This function returns a Date/Time value’s weekday. The result by default ranges from 1 (Sunday) to 7 (Saturday).
  3. BusinessDay_DatePicker: Name of the Power Apps date picker control
Power Apps Troubleshooting Error Messages in Date Picker Control
Power Apps Troubleshooting Error Messages in 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)
Can't convert this data type. Power Apps can't convert this Date to a Boolean
Can’t convert this data type. Power Apps can’t convert this Date to a Boolean

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,

  1. Collweekend is the name of the collection that we have created
  2. WeekDays is the name of the collection header.
  3. 2,3,4,5,6 are the weekday numbers representing the weekdays i.e., Monday, Tuesday, Wednesday, Thursday, and Friday respectively.
Power Apps date picker control disable weekends
Power Apps date picker control disable weekends
  • 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.

Power Apps DatePicker restricts weekends
Power Apps DatePicker restricts weekends
  • 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.
PowerApps DatePicker restrict weekend days
PowerApps DatePicker restrict weekend days
  • Similarly, select a weekend from the date picker control and we can see it will restrict us by displaying a warning message.
PowerApps date picker disable weekends
PowerApps date picker disable weekends

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:

>