Disable Past Dates in Power Apps Date Picker Control

DatePicker controls are a fundamental component in Power Apps, widely used for capturing crucial dates like appointments, deadlines, leave requests, and event registrations. In many business scenarios, it's essential to prevent users from selecting dates that have already passed. For instance, when booking an appointment or submitting a leave request, only the current or future dates should be selectable.

This article will guide you through the process of disabling past dates in a Power Apps DatePicker control, ensuring users can only select valid future dates, thereby enhancing data integrity and user experience.

Why Disable Past Dates?

Consider a Leave Request application. Without proper validation, an employee could mistakenly select a past date, leading to an invalid request. Implementing restrictions ensures that only valid, future dates are selected, streamlining the process and preventing errors.

Common Business Scenarios

Understanding the DatePicker Control

A DatePicker control provides a calendar interface for users to select dates. Power Apps offers several properties that can be configured to control the allowable date ranges.

Default Behavior

By default, a DatePicker control allows users to select past, current, and future dates without any restrictions.

Business Requirement

The common business requirement is to disable past dates, allow the current date, and enable future dates for selection.

Method 1: Using the MinDate Property

The most straightforward approach to disable past dates is by utilizing the MinDate property of the DatePicker control.

By setting the MinDate property to the current date using the Today() function, you effectively disable all dates prior to the current day.

How MinDate Works

The Today() function returns the current system date. When you set DatePicker1.MinDate = Today(), the DatePicker control will only allow selections from the current date onwards. Any date before the current date will be disabled and unselectable.

Example: If today's date is July 15, 2026, then dates from July 15, 2026, onwards will be selectable.

Configuration:

Select the DatePicker control (e.g., DatePickerBooking) and set its MinDate property in the formula bar:

DatePickerBooking.MinDate = Today()

This will visually disable all dates prior to the current date in the calendar interface.

Method 2: Validation Using OnSelect

For more complex validation scenarios or to provide immediate user feedback, you can use the OnSelect property of a button or the OnChange property of the DatePicker itself.

This method involves checking the selected date against the current date and notifying the user if a past date is selected.

Example: For a 'Submit' button, you can implement the following logic:

If(
    DatePicker1.SelectedDate < Today(),
    Notify(
        "Past dates are not allowed",
        NotificationType.Error
    ),
    SubmitForm(Form1)
)

This formula checks if the SelectedDate is less than today's date. If it is, an error message is displayed, and the form submission is blocked. Otherwise, the form is submitted. This provides a better user experience by giving instant feedback.

Method 3: Disable Submit Button

Another effective approach is to disable the submit button if a past date is selected. This visually indicates to the user that the selection is invalid and prevents them from proceeding.

You can achieve this by setting the DisplayMode property of the submit button.

Configuration:

If(
    DatePicker1.SelectedDate < Today(),
    DisplayMode.Disabled,
    DisplayMode.Edit
)

This ensures that the submit button is disabled when a past date is selected, guiding the user to correct their input before they can submit.

Real-World Examples

Leave Request Application

In a leave request application with fields like EmployeeName, LeaveType, StartDate, and EndDate, the StartDate and EndDate DatePicker controls should be configured to only allow today or future dates.

Configuration:

DatePickerStartDate.MinDate = Today()
DatePickerEndDate.MinDate = Today()

This prevents employees from choosing expired dates for their leave requests.

Appointment Booking Example

For a customer appointment booking system, past appointments are not allowed. Setting the MinDate of the appointment DatePicker to Today() ensures customers can only book future appointments.

Event Registration Example

When users register for events, they should not be able to register for past events. Configuring the event DatePicker with DatePickerEvent.MinDate = Today() ensures that only valid future event dates remain selectable.

Using Custom Date Ranges

You can also define custom date ranges beyond simply disabling past dates.

Allowing Bookings After a Certain Period

To allow bookings only after a specific number of days (e.g., 7 days from today), you can adjust the MinDate formula:

DatePicker1.MinDate = Today() + 7

This sets the first available date to 7 days from the current date.

Restricting Future Dates

Conversely, you can limit future selections by setting the MaxDate property:

DatePicker1.MaxDate = Today() + 30

This creates an allowed range from today up to 30 days in the future, which is useful for booking systems with limited availability windows.

Common Power Fx Formulas

Best Practices

Benefits of Disabling Past Dates

Conclusion

Disabling past dates in a Power Apps DatePicker control is a simple yet highly effective technique for improving data quality and user experience. By leveraging the MinDate property, validation formulas, and button restrictions, developers can ensure users select only valid dates that align with business requirements. Whether you are building leave management systems, appointment booking applications, event registration portals, or project planning solutions, restricting past dates is crucial for maintaining accurate and reliable data across your Power Apps.