# Enabling Only Dates in a Specific Date Range using DateTime Picker in ASP.NET MVC

## Environment

\| Product | Date/Time Pickers for ASP.NET MVC |
\| Version | 2023.3.1114 |

## Description

I want to select a DateTime between the current date and the following 30 days using the DateTime Picker in ASP.NET MVC. I would like to restrict the selection to only dates within this range and disable dates outside of it.

## Solution

To achieve this, you need to utilize the [DisableDates handler functionality](https://docs.telerik.com/aspnet-core/api/kendo.mvc.ui.fluent/datepickerbuilder#disabledatessystemstring) of the DateTimePicker in ASP.NET MVC.

Modify the JavaScript logic of the [DateTimePicker Disabled Dates Demo](https://demos.telerik.com/aspnet-mvc/datetimepicker/disable-dates) with the code below:

```javascript
function disableDates(date) {
    var currentDate = new Date();
    currentDate.setDate(currentDate.getDate() - 1);
    var endDate = new Date();
    var monthIndex = (new Date().getMonth() + 1) % 12;
    if (monthIndex == 0) {
        endDate.setYear(endDate.getFullYear() + 1);
    }
    endDate.setMonth(monthIndex);

    if (date && compareDates(date, currentDate, endDate)) {
        return false;
    } else {
        return true;
    }
}

function compareDates(date, startDateRange, endDateRange) {
    if (date.getTime() > startDateRange.getTime() && date.getTime() < endDateRange.getTime()) {
        return true;
    } else {
        return false;
    }
}
```

See the suggested behavior in action in [this Telerik REPL example](https://netcorerepl.telerik.com/mdlmPXvg01qEsg0c37).

## Notes

* This solution uses JavaScript logic to disable the dates outside the specified range.
* The code provided compares the selected date with the current date and the end date (current date + 30 days) to determine if it falls within the range.
* You may need to adjust the logic to fit the specific restriction rules of the scenario at hand.

## More ASP.NET MVC DateTimePicker Resources

* [ASP.NET MVC DateTimePicker Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/editors/datetimepicker/overview)

* [ASP.NET MVC DateTimePicker Demos](https://demos.telerik.com/aspnet-mvc/datetimepicker/index)

* [ASP.NET MVC DateTimePicker Product Page](https://www.telerik.com/aspnet-mvc/datetimepicker)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Client-Side API Reference of the DateTimePicker for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/datetimepicker)
* [Server-Side API Reference of the DateTimePicker for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/datetimepicker)
* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)
* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
