cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Kudo Collector
Kudo Collector

Start and end date validation

How do I make sure the user enters an end date that is greater than or equal to the start date, not before?

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Power Apps
Power Apps

Re: Start and end date validation

You cannot prevent, in the date picker control, that the user select a date outside a certain date range (you can only limit the date picker based on the year). Please consider creating a new feature request in the PowerApps Ideas board for this scenario.

 

What you can do is to show a visual indication to the user that the selection is incorrect. In the example below, I added a label under the start / end date pickers and changed the border color of the pickers to indicate an error:

ForumPost000.PNG

You can accomplish that by setting the following properties (assuming the start / end date picker controls are called respectively datePickerStart / datePickerEnd, and the label that shows the error is called labelInvalidDates):

datePickerStart.BorderColor: If(datePickerEnd.SelectedDate < datePickerStart.SelectedDate, Color.Red, RGBA(101, 128, 187, 1))
datePickerEnd.BorderColor: If(datePickerEnd.SelectedDate < datePickerStart.SelectedDate, Color.Red, RGBA(101, 128, 187, 1))
labelInvalidDates.Visible: datePickerEnd.SelectedDate < datePickerStart.SelectedDate

If the selection is fixed, then the label will disappear, and the border of the date picker controls will return to its default value:

ForumPost001.PNG

Hope this helps!

View solution in original post

Highlighted
Power Apps
Power Apps

Re: Start and end date validation

You can use the DisplayMode property of the submit button to disable it if there are any errors in the form. For example, if you have the start/end dates and also a text input for the name that needs to have at least 5 characters, you can set the following expression to the DisplayMode property of the submit button:

If(
    (datePickerEnd.SelectedDate < datePickerStart.SelectedDate) || Len(textInputName) < 5),
    DisplayMode.Disabled,
    DisplayMode.Edit)

If either the dates are incorrect, or the length of the name is less than 5, then the submit button will be disabled; otherwise it will be active (DisplayMode.Edit means that the control can interact with the user).

View solution in original post

10 REPLIES 10
Highlighted
Power Apps
Power Apps

Re: Start and end date validation

You cannot prevent, in the date picker control, that the user select a date outside a certain date range (you can only limit the date picker based on the year). Please consider creating a new feature request in the PowerApps Ideas board for this scenario.

 

What you can do is to show a visual indication to the user that the selection is incorrect. In the example below, I added a label under the start / end date pickers and changed the border color of the pickers to indicate an error:

ForumPost000.PNG

You can accomplish that by setting the following properties (assuming the start / end date picker controls are called respectively datePickerStart / datePickerEnd, and the label that shows the error is called labelInvalidDates):

datePickerStart.BorderColor: If(datePickerEnd.SelectedDate < datePickerStart.SelectedDate, Color.Red, RGBA(101, 128, 187, 1))
datePickerEnd.BorderColor: If(datePickerEnd.SelectedDate < datePickerStart.SelectedDate, Color.Red, RGBA(101, 128, 187, 1))
labelInvalidDates.Visible: datePickerEnd.SelectedDate < datePickerStart.SelectedDate

If the selection is fixed, then the label will disappear, and the border of the date picker controls will return to its default value:

ForumPost001.PNG

Hope this helps!

View solution in original post

Highlighted
Kudo Collector
Kudo Collector

Re: Start and end date validation

Thank you for your help!  This works good but unfortunately it still lets you submit even when the fields are red because of wrong dates.  How can I stop it from submitting?

 

For that matter, how do you stop it from submitting on any error?

Highlighted
Power Apps
Power Apps

Re: Start and end date validation

You can use the DisplayMode property of the submit button to disable it if there are any errors in the form. For example, if you have the start/end dates and also a text input for the name that needs to have at least 5 characters, you can set the following expression to the DisplayMode property of the submit button:

If(
    (datePickerEnd.SelectedDate < datePickerStart.SelectedDate) || Len(textInputName) < 5),
    DisplayMode.Disabled,
    DisplayMode.Edit)

If either the dates are incorrect, or the length of the name is less than 5, then the submit button will be disabled; otherwise it will be active (DisplayMode.Edit means that the control can interact with the user).

View solution in original post

Highlighted
New Member

Re: Start and end date validation

been trying to do that...but nothing working....... doing a similar thing in my project working on

Highlighted
Frequent Visitor

Re: Start and end date validation

Worx very well....thx a lot

Highlighted
Helper IV
Helper IV

Re: Start and end date validation

Hi,

 

i have a similar date validation scenario but im using datetime picker controls instead of simple dates.

SO when i apply the logic as pasted above, it doesnt validate on the change. in other words teh validation does run on the change that i do or after i fix teh date value. so my error label continues to show and even teh border color

 

formula used - 

If(ThisItem.'Start Time' > ThisItem.'End Time', Color.Red, RGBA(101, 128, 187, 1))//RGBA(0, 18, 107, 1)

error label.visbile property set to = If('End Time_DataCard4'.BorderColor=Red,true,false)

 

ANy suggestions if is there any OnChange property that i should fix too. ( Although i tried that on the HourValue and DateValue cards, but to no luck)

validation isnt re-running when i change teh picker control values.

Highlighted
Helper IV
Helper IV

Re: Start and end date validation

Hi,

 

ANy help with start and end time validation check please ?

The validation logic doesnt re runs when datetime picker control's value is changed

 

Highlighted
Helper IV
Helper IV

Re: Start and end date validation

Hi @CarlosFigueira 

Could you provide soem insights on the similar situation but with datetime picker control?

when i chaneg my hour/date/minute picker values, teh validation isnt rerunning.

 

How shoudl i make it work ?

Highlighted
Helper I
Helper I

Re: Start and end date validation

how to fix this when it also has time say they put in the same date but the time is other way.

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,963)