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 / Can the date picker fi...
Power Apps
Answered

Can the date picker field be filtered to only a select range of dates?

(0) ShareShare
ReportReport
Posted on by 143

Hey,

I am currently a baby developer with BIG dreams.
I am creating a custom TimeSheet App, using a PowerApp course (#2) and a GitHub Template training (#1).

Here is my goal:
Currently we have a SharePoint list with customized form.  We would like to transition to a self-contained app.

Both of the items I am using above create entries based on selected week. Both by listing all the dates in the gallery.  One option allows for multiple entries for the same week and the other does not.

The user needs to be able to enter multiple entries in the same week. Some will be within the same day.  I have created the app using the concept from #1, because it allows for as many lines as necessary for a single week, but the design of #2 for the gallery, contains each date as a separate entry or line within the gallery.

My question is, can a date picker be limited to only the dates within the selected week or do I need to create a custom drop-down for the date fields?

Thanks

Tammy

Categories:
I have the same question (0)
  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    Hi @Tj7933, limiting the input of a date picker to only this week is certainly possible.

     

    (1) Set the DefaultDate property to Today()

     

    (2) Write the following code in the OnChange property:

     

    If(
     Self.SelectedDate < DateAdd(
     Today(),
     1 - Weekday(
     Today(),
     StartOfWeek.Monday
     ),
     Days
     ) || Self.SelectedDate > DateAdd(
     Today(),
     1 - Weekday(
     Today(),
     StartOfWeek.Monday
     ) + 6,
     Days
     ),
     Notify(
     "Please select a date within this week",
     NotificationType.Error,
     3000
     ); Reset(Self);
    )

     

    When picking a date, the code above checks if it is between Monday to Sunday. Picking a date outside that week will throw an error and reset the date picker back to the default, being Today(). If you don't want to count the weekend, change the +6 to +4.

     

    Note: if the allowed week can change, you will have to change the Today() in the DefaultDate & all Today() mentions in the OnChange code to the selected date value.

     

    If this solves your question, would you be so kind as to accept it as a solution.

    Thanks!

  • Tj7933 Profile Picture
    143 on at

    It is so much fun retyping our my question.  @LaurensM , the response was perfect for the start date, but there are 3 errors I am trying to evaluate for the end date.  It keeps saying that I either miss a character or have an extra character.  Nothing is underlined to show where my issue exists. Do you see my error?

    If(
     Self.SelectedDate < DateValue(lblWeekStart.Text),
     Days
     || Self.SelectedDate > DateValue(lblSelectedDate.Text),
     Days,
     Notify(
     "Please select a date within the week selected.",
     NotificationType.Error,
     3000
     ); Reset(Self),
    
    If(
     Self.SelectedDate < (dpStartDate_1.SelectedDate), Days,
     Notify(
     "End Date is less than Start Date.",
     NotificationType.Error,
     3000
     ); Reset(Self),
    
    If(
     Self.SelectedDate > ((dpStartDate_1.SelectedDate)+1), Days,
     Notify(
     "End Date is greater than 24 hours from Start Date.",
     NotificationType.Error,
     3000
     ); Reset(Self);

     

  • Tj7933 Profile Picture
    143 on at

    Ok, I used your code, and it worked.  My problem is it is checking the two fields before they are finished so the user keeps getting the red warning message.  For example, The Start Date is set to 18/11 and I goto enter the end date and the warning comes up before I take any action.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 494

#2
WarrenBelz Profile Picture

WarrenBelz 352 Most Valuable Professional

#3
11manish Profile Picture

11manish 323

Last 30 days Overall leaderboard