Date & time

DatePickerControl · TimePickerControl · DateRangePickerControl · CalendarControl · TimeSpanPickerControl

Let users type or pick a date, a time, a range or a duration.

Overview

DatePickerControl is a Blazor date picker: users type a date in any of sixteen formats or pick it from a calendar. Its siblings cover the rest of a booking: TimePickerControl lists times in steps, DateRangePickerControl takes a start and an end, CalendarControl can disable days such as weekends, and TimeSpanPickerControl takes a duration. All five bind two ways; the time and range pickers also report bad entries to a surrounding EditForm.

Examples

#Date, time and duration

Book an airport transfer: type a date or open the calendar, which only offers the days of the trip through MinDate and MaxDate. A typed date outside moves the bound date to the first or last day of the trip, though the box keeps the typed text. The time list runs 6:00 AM to 10:00 PM in half hours, and the line below follows every change.

Pickup date
Pickup time
Car needed for
h
m

Car for Albus Door, Lisbon airport to the old town: Sun Dec 13, 9:30 AM to 11:00 AM. The trip runs Dec 13 to Dec 17.

#Date range

Pick a check-in and a check-out, or press a preset, which calls SetValueAsync: one CalendarRange binds both boxes and the popup, and DisabledDate blocks the sold-out dates. The popup refuses a range that includes one; typed dates still reach the page with an Error, so the quote checks it first.

Amalfi hotel for Albus Door: 3 nights, Sun Dec 20 to Wed Dec 23, $540 at $180 a night. Dec 14 to Dec 16 is sold out.

#Calendar, several dates

Click the departures a group could take: each day shows its price through DayTemplate, Mondays are disabled, and the heading switches to year and decade views.

MonTueWedThuFriSatSun

2 departures: Tue Dec 8 ($80), Thu Dec 10 ($80). Cheapest: $80.

Documentation

ParameterTypeDefaultDescription
ValueDateTime?nullSelected date, or date and time with ShowTime. Two-way with @bind-Value.
ValueChangedEventCallback<DateTime?>—Fires when typed text parses (Enter or blur) or a day is picked.
ValueExpressionExpression<Func<DateTime?>>?nullSet by @bind-Value, but the date picker never reads it: it reports nothing to an EditContext.
Formatstring?"MM/dd/yyyy" (with time: "MM/dd/yyyy hh:mm tt")Display format. Typed text is tried against this first, then the built-in list.
Placeholderstring?the formatInput placeholder.
ShowTimeboolfalseAdds a time box to the drop-down and time formats to parsing.
MinDate / MaxDateDateTime?nullDays outside are disabled in the calendar. A typed date outside is not refused: the bound value moves to the nearest bound, but the box keeps showing the typed date. The time picker refuses its own.
ShowCalendarSidebarboolfalseExpandable sidebar of shortcuts: Today, Yesterday, Tomorrow, Start and End of Week, Next Week, Start and End of Month, Clear Date.
ParseFormatsIEnumerable<string>?nullExtra formats tried before the sixteen built-in ones (ISO, US, day-month, dd-MMM-yy, digit runs).
CultureCultureInfo?invariantFormatting and parsing culture; null uses the invariant culture (typed text also falls back to the current culture). Month names in the drop-down follow the current culture.
ShowTriggerButtonbooltrueShows the 📅 button. Without it Enter on an empty field no longer opens the calendar.
OpenCalendarOnDoubleClickboolfalseDouble-click in the input opens the calendar.
AutoFocusboolfalseFocuses the input once after first render.
AriaLabelstring?nullAccessible name of the input.
ValidationChangedEventCallback<string?>—Fires with the parse message, or null when the text is valid again.
Enabled / Visible / Id / CssClass / Style (base)—All honored on the host.
Grid-cell hosting—OpenOnRender, InitialText, Uncontrolled, InputValueChanged, ElementReferenceCaptured, OnKeyDown, CalendarButtonKeyDown serve the grid's cell editor; see the source comments before using them in a form.
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.