How to validate the Date control in Power Apps to only allow selection of Tuesday and Thursday?

Summary

I needed to restrict the date selection in the Power Apps form to only allow Tuesday and Thursday.

Step By Step Solution

I assume you know how to create Power Apps form app.

Step # 1 I the BorderColor property of the Date control (in my case DateValue2) put the following formula. The Weekday function will provide the number for Tue and Thu.

// if parent error is blank or
//    selected date is Tue or Thu the border color is normal
If(
    Coalesce(
        (Weekday(
            DateValue2.SelectedDate,
            StartOfWeek.Sunday
        ) = 3) ||
        (Weekday(
            DateValue2.SelectedDate,
            StartOfWeek.Sunday
        ) = 5),
        IsBlank(Parent.Error)

    ),
    Parent.BorderColor,
    Color.Red
)
BorderColor

Step # 2 In the Text property of the ErrorMessage Control of the DataCard add the following formula.

Coalesce(
    Parent.Error,
    If(
        ((Weekday(
            DateValue2.SelectedDate,
            StartOfWeek.Sunday
        ) <> 5) && (Weekday(
            DateValue2.SelectedDate,
            StartOfWeek.Sunday
        ) <> 3)),
        "Date must be for Tuesday or Thursday only"
    )
)
Text property

Conclusion

Currently, the out of the box date control does not provide any validation, this is an alternative approach to validate and restrict the days. I hope it is useful to you for your scenario.

About Pankaj

I am a Developer and my linked profile is https://www.linkedin.com/in/pankajsurti/
This entry was posted in Power Apps. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s