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 / Datepicker onChange/on...
Power Apps
Suggested Answer

Datepicker onChange/onSelect not working

(3) ShareShare
ReportReport
Posted on by 22

Hi All

I am trying to limit the range of dates that can be selected from the datepicker so I added some formulas to datepicker onSelect and onChange:

 

If(DateDiff(DatePicker1.SelectedDate,Today(),Days) > 5, 
 UpdateContext({DateWorning:"NO", TheDate:Today()}) , 
 UpdateContext({DateWorning:"Yes", TheDate:Today()}) )

 

 also tried

 

UpdateContext({DateWorning: If(DateDiff(DatePicker1.SelectedDate,Now(),Days) > 5,"NO", "Yes"), 
 TheDate:If(DateDiff(DatePicker1.SelectedDate,Now(),Days) > 5, Today(), DatePicker1.SelectedDate) }) 

 

but it doesnt change  neither DateWorning or TheDate

Any Ideas?

Thanks

Categories:
I have the same question (0)
  • iAm_ManCat Profile Picture
    18,256 Most Valuable Professional on at

    Hi!

     

    I'm not sure about the OnSelect event, but I think the OnChange event only triggers when a date is selected, not when you type into the control (at least that was the case the last time I used it).

     

    I'd recommend replacing your default datepicker with this one by @PowerAddict:

    https://powerusers.microsoft.com/t5/Canvas-Apps-Components-Samples/Reusable-Revamped-Date-Picker-Control-v3/m-p/590606#M200

     

     

     

    Then you could modify the component to limit date ranges,

     

    Cheers,

    Sancho

  • PowerAddict Profile Picture
    7,316 Most Valuable Professional on at

    Thank you @iAm_ManCat!

     

    @k_romych I have a significantly better version of the date picker component which I will be releasing this week. You can either take that and customize it or if you want, I can try to add the feature that you are requesting here. 

     

    ---
    If you like this reply, please give kudos (Thumbs Up). And if this solves your problem, please mark this reply as a solution by selecting Accept as Solution. This makes it easier for others to find answers to similar questions. 

     

    Thanks!

    Hardit Bhatia

    Microsoft Business Applications MVP

    Blog | Twitter | LinkedIn | Facebook | YouTube  |  Email

  • k_romych Profile Picture
    22 on at

    @PowerAddict  - I am getting "There was an error opening the file" when trying to import your .msapp

  • CodeMorgan Profile Picture
    28 on at

    The PowerApps modern date picker doesn't seem to be any better at OnChange trigger events. I have one in a gallery and it simply does not perform the OnChange event even though I can put the exact same script in an icon with an Classic date picker and the script works. Microsoft is really leaving us developers hung out to dry with their untested horrible controls.

  • Suggested answer
    brightfame Profile Picture
    5 on at
    Four years later, I'm finding out that OnSelect fires for both OnSelect and OnChange events.  Not that it helps now, but the OP's code should be applied to OnSelect and read:
     
    If(DateDiff(Today(),Self.SelectedDate) > 5,
     UpdateContext({DateWorning:"NO", TheDate:Today()}) ,
     UpdateContext({DateWorning:"Yes", TheDate:Today()}) )

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 610

#2
Haque Profile Picture

Haque 317

#3
WarrenBelz Profile Picture

WarrenBelz 315 Most Valuable Professional

Last 30 days Overall leaderboard