|
| 1 | +--- |
| 2 | +title: Overview |
| 3 | +page_title: Date-Time Picker for Blazor Overview |
| 4 | +description: Overview of the DateTime Picker for Blazor |
| 5 | +slug: components/datetimepicker/overview |
| 6 | +tags: telerik,blazor,datetime,picker,datetimepicker,overview |
| 7 | +published: True |
| 8 | +position: 0 |
| 9 | +--- |
| 10 | + |
| 11 | +# DateTime Picker Overview |
| 12 | + |
| 13 | +The DateTime Picker component allows the user to choose both a date and a time from a visual list in a dropdown, or to type it into a [date input]({%slug components/dateinput/overview%}) that can accept only DateTime values. You can control the format shown in the input and respond to [events]({%slug components/datetimepicker/events %}). |
| 14 | + |
| 15 | +To use a Telerik DateTime Picker for Blazor, add the `TelerikDateTimePicker` tag. |
| 16 | + |
| 17 | +>caption Basic datetime picker with custom format, min and max |
| 18 | +
|
| 19 | +````CSHTML |
| 20 | +Selected time: @selectedTime |
| 21 | +<br /> |
| 22 | +
|
| 23 | +<TelerikDateTimePicker Min="@Min" Max="@Max" @bind-Value="@selectedTime" |
| 24 | + Format="dd MMM yyyy HH:mm:ss" Width="250px"></TelerikDateTimePicker> |
| 25 | +
|
| 26 | +@code { |
| 27 | + private DateTime? selectedTime = DateTime.Now; |
| 28 | + public DateTime Min = new DateTime(1990, 1, 1, 8, 15, 0); |
| 29 | + public DateTime Max = new DateTime(2025, 1, 1, 19, 30, 45); |
| 30 | +} |
| 31 | +```` |
| 32 | + |
| 33 | +>caption The result of the snippet above and the behavior of the component |
| 34 | +
|
| 35 | + |
| 36 | + |
| 37 | +>caption Component namespace and reference |
| 38 | +
|
| 39 | +````CSHTML |
| 40 | +@using Telerik.Blazor.Components |
| 41 | +
|
| 42 | +<TelerikDateTimePicker @ref="@theDateTimePickerRef" @bind-Value="@selectedTime"></TelerikDateTimePicker> |
| 43 | +
|
| 44 | +@code { |
| 45 | + private DateTime? selectedTime = DateTime.Now; |
| 46 | + // the datetime picker is a generic component and its type comes from the value field type |
| 47 | + Telerik.Blazor.Components.TelerikDateTimePicker<DateTime?> theDateTimePickerRef { get; set; } |
| 48 | +} |
| 49 | +```` |
| 50 | + |
| 51 | +The DateTimePicker component exposes the following features: |
| 52 | + |
| 53 | +* `Class` - the custom CSS class rendered on the wrapping element. |
| 54 | +* `Enabled` - Specifies whether typing in the input and opening the dropdown are allowed. |
| 55 | +* `Format` - Specifies the format of the DateInput of the DateTimePicker. Defaults to `MM/dd/yyyy HH:mm:ss` (24 hour time short month and date). Read more in the [Supported Formats]({%slug components/dateinput/supported-formats%}) article. |
| 56 | +* `Min` - The earliest date and time that the user can select in the dropdown. |
| 57 | +* `Max` - The latest date and time that the user can select in the dropdown. |
| 58 | +* `Value` - The current value of the input. Can be used for binding. |
| 59 | +* `Width` - Defines the width of the DateTimePicker. |
| 60 | +* Validation - see the [Input Validation]({%slug common-features/input-validation%}) article. |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +When using the dropdown to edit dates, you must click the "Set" button to commit the date. It is located in the Time portion of the dropdown (you will be navigated to it automatically upon selecting a date). Clicking "Cancel", or outside of the dropdown without clicking "Set", will revert the time to the original value. You can also commit a date by clicking the "NOW" button which will choose the current time. |
| 65 | + |
| 66 | +The time format specifiers in the `Format` control the tumblers available in the dropdown. For example, the `HH` specifier will result in a hour selector in a 24 hour format. If you also add the `tt` specifier, you will also get the AM/PM tumbler, but the 24 hour format will still be used. This means that you can also add several tumblers for the same time portion if the format string repeats them. |
| 67 | + |
| 68 | + |
| 69 | +## See Also |
| 70 | + |
| 71 | + * [Live Demo: DateTime Picker](https://demos.telerik.com/blazor-ui/datetimepicker/index) |
| 72 | + * [Input Validation]({%slug common-features/input-validation%}) |
| 73 | + * [Supported Input Date Formats]({%slug components/dateinput/supported-formats%}) |
0 commit comments