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 / ShP Online Form - Date...
Power Apps
Unanswered

ShP Online Form - Date Picker - limit the possibility of choosing a date no more than 7 days in the past, no future

(0) ShareShare
ReportReport
Posted on by 3

Hello all,

I'm trying to modify the ShP Online form of list, where is a date and time column called "Day" as following:

I need to enable the selection of a date when filling out the form in a specific month (May 2023), with the option to select a date no more than 7 days ago (including the record day) and without the option/deny the option to select future date.

I imagine that if a date outside the range is selected, an error message will be displayed and the save button will simply not work/do nothing until the correct date is selected.

So far, I have something like sample below, but I lack knowledge, or I don't know how to correctly define OnNew/OnSelect/OnSave or OrEdit, either directly in the Date Picker or in the SharePointIntegration -> Action field, and I'm not quite sure whether my condition is about right.. (at the moment, it's directly in the Date Picker in the DataCardValue4 - OnChange field.

 

 

If(Month(DataCardValue4.SelectedDate) = 5 && DataCardValue4.SelectedDate >= DateAdd(Today(),-7) && DataCardValue4.SelectedDate > Today(), UpdateContext({varDate: DataCardValue4.SelectedDate}), Notify("It is possible to record only a trip that took place less than 7 days ago", NotificationType.Error))

 

 

Could you please suggest how to finish the condition, how the code should look like and how to decide whether to modify the DataCardValue or SharePointIntegration part?

I apologize for basics, I just started with PowerPlatform/PowerFX and avoided excel (Cloud Infra Administrator) so there is definitely space for improvement and sharpen the learing curve.

 Thank you!

Categories:
I have the same question (0)
  • mmollet Profile Picture
    3,187 on at

    What I like to do when I'm doing what is essentially input validation like this is manipulate the display mode of the 'submit' button and the border color of the control. So if the date picker's date chosen is outside the valid range then the display mode of the submit button will be disabled instead of edit and the border of said date picker will be red or black depending on the same date chosen. This both prevents invalid dates from being submitted as well as shows the user where the error is. 

     

    Another thing I see is you are comparing the selected date to month 5 which is static and won't change as the months change. If you want to make that dynamic just use Month(Today()) or Month(Now()) instead of the 5. The issue with this is you can have a case where this will invalidate a possibly valid input. The way this is set up if someone picked a date 5 days in the past but it was the 1st, 2nd, 3rd, 4th. or 5th day of the month then that will take the date into the previous month and invalidate it based on this condition. You may not need this code at all: 

    Month(DataCardValue4.SelectedDate) = 5

     

    Here is some pseudo-code for you to start with:

    SubmitButton.DisplayMode 

    // if(the date chosen is between today's date and the date 7 days before today, edit, disabled)
    If(DataCardValue4.SelectedDate >= DateAdd(Today(),-7) && DataCardValue4.SelectedDate <= Today(), 
     DisplayMode.Edit, DisplayMode.Disabled)

     

    DatePicker's Border Color

    // if(the date chosen is between today's date and the date 7 days before today,Black,Red)
    If(DataCardValue4.SelectedDate >= DateAdd(Today(),-7) && DataCardValue4.SelectedDate <= Today(), 
     Color.Black, Color.Red)

     

    You can add a notify statement if you want into that as well.

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!

Leaderboard > Power Apps

#1
Haque Profile Picture

Haque 85

#2
WarrenBelz Profile Picture

WarrenBelz 76 Most Valuable Professional

#3
Kalathiya Profile Picture

Kalathiya 38 Super User 2026 Season 1

Last 30 days Overall leaderboard