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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Restrict date field to...
Power Apps
Suggested Answer

Restrict date field to month start days only

(1) ShareShare
ReportReport
Posted on by 2
I want to restrict user to select only starting day of the month when setting it on model driven app. For example, if the user is trying to select Aug 8th, 2024, it should not let the user select it and throw an error message, unless the user selects 1st Aug, 2024.
I do not want to use canvas app for this. Trying to solve this using business rules. Any help is appreciated, thank you in advance.
I have the same question (0)
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,433 Super User 2025 Season 2 on at
    HI
     
    While you can do things with JavaScript (assuming you mean on a Form), have you thought about creating either a Choice, or a LookUp table.
     
    The look up table would only have 12 dates in it, the 1st of each month, then only let them select from that field on your form, then there is no way for them to select anything but the 1st of a month.
  • Suggested answer
    lbendlin Profile Picture
    8,479 Super User 2025 Season 2 on at
    a) have a year and month selector rather than a date selector
    b) accept whatever the user enters and then quietly replace the day value with 1 in the backend.
  • Suggested answer
    Ram Prakash Duraisamy Profile Picture
    5,593 Super User 2025 Season 2 on at
    Hi,
     
    You can use below JAVASCRIPT to achieve the same
     
     
     
    function validateDate(executionContext) {
        var formContext = executionContext.getFormContext();
        var dateField = formContext.getAttribute("your_date_field_name");
        if (dateField) {
            var selectedDate = dateField.getValue();
            if (selectedDate) {
                var day = selectedDate.getDate();
                if (day !== 1) {
                    // Set error message
                    dateField.setValue(null); // Optionally clear the field
                    formContext.getControl("your_date_field_name").setNotification("Please select the 1st day of the month only.", "error");
                } else {
                    // Clear error message if date is valid
                    formContext.getControl("your_date_field_name").clearNotification("error");
                }
            }
        }
    }

     
  • WarrenBelz Profile Picture
    153,079 Most Valuable Professional on at
    Try this OnChange of your Date Picker
    UpdateContext(
       {
          varFirst: 
          Date(
             Year(Self.SelectedDate),
             Month(Self.SelectedDate),
             1
          )
       }
    );
    Reset(Self)
    then the DefaultDate
    If(
       Value(varFirst) > 1,
       varFirst
    )
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)     Visit my blog Practical Power Apps    Buy me a coffee
     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard