web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Restrict future date a...
Power Apps
Unanswered

Restrict future date and time in canvas app

(0) ShareShare
ReportReport
Posted on by 237

 

Hi Community Team,

 

 My requirement is User select future date and time show error message and disable submit button.

the error message update dynamically .

Powerappsuser11_0-1686307879351.png

 

Categories:
I have the same question (0)
  • Shaheer Ahmad Profile Picture
    2,194 Moderator on at

    To restrict the selection of future date and time in a Canvas app and display an error message while disabling the submit button, you can use a combination of controls, formulas, and properties. Here's a step-by-step guide on how to achieve this:

    1. Create a Date Picker control and a Time Picker control in your Canvas app. Let's assume you have named them DatePicker1 and TimePicker1, respectively.

    2. Add a Label control to display the error message. Let's name it ErrorMsgLabel.

    3. Set the OnChange property of the DatePicker to a formula that checks if the selected date and time are in the future and displays the error message accordingly. If the date and time are valid, you can perform the desired submit action. Here's an example formula:

     

    If(
     DateTimeValue(Text(DatePicker1.SelectedDate & " " & TimePicker1.SelectedTime)) > Now(),
     UpdateContext({ ShowError: true }),
     SubmitForm(Form1)
    )

     

     

    In this formula, Form1 represents the form you want to submit.

    1. Set the Text property of the ErrorMsgLabel to the error message you want to display. You can use a variable to store the dynamic error message. Here's an example:

     

    If(ShowError, "Invalid date and time selected.", "")

     

     

    1. Finally, set the DisplayMode property of the DropDown to disable it when the error message is displayed:

     

    If(ShowError,DisplayMode.Disable,DisplayMode.Edit)

     

     

    That's it! Now, when the user selects a future date and time, the error message will be displayed, and the submit button will be disabled. Adjust the formulas and error message text to fit your specific requirements.

     

  • Powerappsuser11 Profile Picture
    237 on at

    Hi @ShaheerAhmad 

     

     Thank you for quick response.

     

      Above code not working for me.

     in my scenario 1 datepicker and 2 dropdowns(hours and minutes)

    below is my code,please  provide correct one this requirement.

    If(DateTimeValue(Text(DatePicker1.SelectedDate&""&Dropdown5.Selected.Value &""&Dropdown6.Selected.Value))>Now(), 

  • Shaheer Ahmad Profile Picture
    2,194 Moderator on at

    Apologies for the confusion. If you're using a single DatePicker and two Dropdown controls for hours and minutes, you can modify the formula accordingly. Here's an updated version of the code to achieve the desired functionality:

    1. Assuming you have a DatePicker named DatePicker1, a Dropdown for hours named DropdownHours, and a Dropdown for minutes named DropdownMinutes, update the OnChange property of your  (DropDown) with the following formula

     

    If(
     DateTimeValue(Text(
     DatePicker1.SelectedDate & " " &
     DropdownHours.Selected.Value & ":" &
     DropdownMinutes.Selected.Value
     )) > Now(),
     UpdateContext({ ShowError: true }),
     UpdateContext({ ShowError: false })
    )

     

    1. Set the Text property of the error message label (ErrorMsgLabel) to display the dynamic error message:

     

    If(ShowError, "Invalid date and time selected.", "")

     

    1. Finally, set the Disabled property of the SubmitButton to disable it when the error message is displayed:

     

    If(ShowError,DisplayMode.Disable,DisplayMode.Edit)

     

     

    Make sure to adjust the control names and the form you want to submit based on your app's specific setup.

    This updated code should properly compare the selected date, hours, and minutes with the current date and time. If the selected date and time are in the future, the error message will be displayed, and the submit button will be disabled.

  • Powerappsuser11 Profile Picture
    237 on at

     

    Hi @ShaheerAhmad 

     Thank you so much for your efforts on requirement ,now no errors but error message not displayed when select future date and time.please rectify the error.

    If(ShowError, "Invalid date and time selected.", "")

    Above formula in doublequots what value required.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 893

#2
Valantis Profile Picture

Valantis 571

#3
11manish Profile Picture

11manish 482

Last 30 days Overall leaderboard