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 / 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,963 Moderator 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,715 Super User 2026 Season 1 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,846 Super User 2026 Season 1 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
    155,450 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

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 833

#2
Valantis Profile Picture

Valantis 563

#3
Haque Profile Picture

Haque 383

Last 30 days Overall leaderboard