# ASP.NET Core DatePicker Overview

The Telerik UI DatePicker TagHelper and HtmlHelper for ASP.NET Core are server-side wrappers for the Kendo UI DatePicker widget.

The DatePicker enables the user to select a date from a calendar or through a direct input. It provides options for using custom templates for its **Month** view, setting minimum and maximum dates, a start view, and a depth for navigation.

* [Demo page for the DatePicker HtmlHelper](https://demos.telerik.com/aspnet-core/datepicker/index)

* [Demo page for the DatePicker TagHelper](https://demos.telerik.com/aspnet-core/datepicker/tag-helper)

## Basic Configuration

The following example demonstrates the basic configuration for the DatePicker.

```Razor HtmlHelper
    @(Html.Kendo().DatePicker()
        .Name("datepicker") // The name of the DatePicker is mandatory. It specifies the "id" attribute of the widget.
        .Min(new DateTime(1900, 1, 1)) // Sets the min date of the DatePicker.
        .Max(new DateTime(2099, 12, 31)) // Sets the max date of the DatePicker.
        .Value(DateTime.Today) // Sets the value of the DatePicker.
    )
```

```Razor TagHelper
    <kendo-datepicker name="datepicker"
        min="new DateTime(1900, 1, 1)"
        max="new DateTime(2099, 12, 31)"
        value="DateTime.Today">
    </kendo-datepicker>
```

> Starting with the 2024 Q3 release, the HtmlHelper version of the component supports [declarative initialization](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/helper-basics/declarative-initialization).

## Model Binding

The DatePicker component respects DataAnnotations when the `DatePickerFor(m=>m.Property)` method is used. Besides the `[Required]` attribute, the `[DisplayFormat]` and `[Range]` attributes are also supported. The [`Format`](https://www.telerik.com/aspnet-core-ui/documentation/api/kendo.mvc.ui.fluent/datepickerbuilder#formatsystemstring) configuration will be set to the provided DisplayFormat and the [`Min`](https://www.telerik.com/aspnet-core-ui/documentation/api/kendo.mvc.ui.fluent/datepickerbuilder#minsystemstring) and [`Max`](https://www.telerik.com/aspnet-core-ui/documentation/api/kendo.mvc.ui.fluent/datepickerbuilder#maxsystemstring) configurations will be set based on the range provided.

```Razor HtmlHelper
    @(Html.Kendo().DatePickerFor(m=>m.MyDateTimeProperty))
```

```Razor TagHelper
    <kendo-datepicker for="MyDateTimeProperty"
    </kendo-datepicker>
```

```C#
    [Required]
    [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
    [Range(typeof(DateTime), minimum:"01/01/2023", maximum:"31/12/2023")]
    public DateTime MyDateTimeProperty{ get; set; }
```

## DateOnly compatability

As of the 2024 Q4 Release the ASP.NET Core DatePicker is compatible with the [`DateOnly`](https://learn.microsoft.com/en-us/dotnet/api/system.dateonly?view=net-8.0) type. Following this release you can also set the value of the component to a `DateOnly` property:

```Razor HtmlHelper
    @(Html.Kendo().DatePicker().Name("datePicker").Value(new DateOnly(2024,5,6)))
```

```Razor TagHelper
    <kendo-datepicker name="datePicker" value="new DateOnly(2024,5,6)">
    </kendo-datepicker>
```

## Functionality and Features

| Feature                                                                                                                             | Description                                                                                                                                                                                 |
| ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Disabled dates](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/editors/datepicker/disabled-dates)               | The DatePicker allows you to disable specific days that are not intended for user interaction.                                                                                              |
| [Selected dates](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/editors/datepicker/selected-dates)               | The DatePicker allows you to render a pre-selected date upon loading.                                                                                                                       |
| [Start view and navigation depth](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/editors/datepicker/nav-depth)   | You can also set the initial view the DatePicker renders and define the navigation depth of its views.                                                                                      |
| [Validation](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/editors/datepicker/validation)                       | The DatePicker keeps its input value unchanged even when the typed date is invalid.                                                                                                         |
| [Calendar types](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/editors/datepicker/calendar-types)               | Even though, by default, the DatePicker supports only the Gregorian calendar, you can still work around this behavior and render other calendar types.                                      |
| [Week number column](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/editors/datepicker/week-number-column)       | The DatePicker provides options for rendering a column which displays the number of the weeks within the current Month view.                                                                |
| [DateInput integration](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/editors/datepicker/dateinput-integration) | The fluent integration between the DatePicker and the DateInput allows you to take advantage of the natively available features of both components.                                         |
| [Templates](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/editors/datepicker/templates)                         | You can customize the content and look and feel of the DatePicker by utilizing templates.                                                                                                   |
| [Accessibility](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/editors/datepicker/accessibility/overview)        | The DatePicker is accessible for screen readers, supports WAI-ARIA attributes, delivers keyboard shortcuts for faster navigation, and allows you to render it in a right-to-left direction. |
| [Automatic Correction](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/editors/datepicker/auto-adjust)            | You can configure whether the component will autocorrect the user's input when the `Min` and `Max` values are set.                                                                          |

## Next Steps

* [Getting Started with the DatePicker](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/editors/datepicker/getting-started)

* [Basic Usage of the DatePicker HtmlHelper for ASP.NET Core (Demo)](https://demos.telerik.com/aspnet-core/datepicker/index)

* [Basic Usage of the DatePicker TagHelper for ASP.NET Core (Demo)](https://demos.telerik.com/aspnet-core/datepicker/tag-helper)

* [DatePicker in Razor Pages](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/editors/datepicker/razor-pages)

## See Also

* [Using the API of the DatePicker HtmlHelper for ASP.NET Core (Demo)](https://demos.telerik.com/aspnet-core/datepicker/api)
* [Server-Side API](https://www.telerik.com/aspnet-core-ui/documentation/api/datepicker)
* [Knowledge Base Section](https://www.telerik.com/aspnet-core-ui/documentation/knowledge-base)
