Introducing PrimeReact v11-alpha 🎉Discover Now
styledForm

DatePicker

DatePicker is a form component to work with dates.

Pick your departure and return dates · Free cancellation
preview

Usage#

import { DatePicker } from '@primereact/ui/datepicker';
<DatePicker.Root>
    <DatePicker.Input />
    <DatePicker.Clear />
    <DatePicker.Trigger>
        <DatePicker.Value />
        <DatePicker.Indicator />
    </DatePicker.Trigger>
    <DatePicker.Portal>
        <DatePicker.Positioner>
            <DatePicker.Popup>
                <DatePicker.Calendar>
                    <DatePicker.Header>
                        <DatePicker.Prev />
                        <DatePicker.Title>
                            <DatePicker.SelectMonth />
                            <DatePicker.SelectYear />
                            <DatePicker.Decade />
                        </DatePicker.Title>
                        <DatePicker.Next />
                    </DatePicker.Header>
                    <DatePicker.Table>
                        <DatePicker.TableHead />
                        <DatePicker.TableBody />
                        <DatePicker.TableBody view="month" />
                        <DatePicker.TableBody view="year" />
                    </DatePicker.Table>
                    <DatePicker.Buttonbar />
                </DatePicker.Calendar>
                <DatePicker.Time />
            </DatePicker.Popup>
        </DatePicker.Positioner>
    </DatePicker.Portal>
</DatePicker.Root>

Examples#

Basic#

Select a single date from an interactive calendar popup.

basic-demo

Format#

Default date format is mm/dd/yy which can be customized using the dateFormat property. Following options can be a part of the format.

  • d - day of month (no leading zero)
  • dd - day of month (two digit)
  • o - day of the year (no leading zeros)
  • oo - day of the year (three digit)
  • D - day name short
  • DD - day name long
  • m - month of year (no leading zero)
  • mm - month of year (two digit)
  • M - month name short
  • MM - month name long
  • y - year (two digit)
  • yy - year (four digit)
  • @ - Unix timestamp (ms since 01/01/1970)
  • ! - Windows ticks (100ns since 01/01/0001)
  • '...' - literal text
  • '' - single quote
  • anything else - literal text
format-demo

Icon#

An additional icon is displayed next to the input field.

icon-demo

Value & Trigger#

Use DatePicker.Trigger and DatePicker.Value to build custom trigger UIs without the default input. Supports date range pickers with formatted display, multi-date selection with removable chips, and custom trigger buttons with flexible layouts.

value-trigger-demo

Min / Max#

Boundaries for the permitted dates that can be entered are defined with minDate and maxDate properties.

min-max-demo

Multiple#

In order to choose multiple dates, set selectionMode as multiple. In this mode, the value binding should be an array.

multiple-demo

Range#

A range of dates can be selected by defining selectionMode as range, in this case the bound value would be an array with two values where first date is the start of the range and second date is the end.

range-demo

Button Bar#

When Buttonbar component is used, today and clear buttons are displayed at the bottom of the calendar panel.

buttonbar-demo

Time#

A time picker is displayed when DatePicker.Time component is used where 12/24 hour format is configured with hourFormat property. In case, only time needs to be selected, add timeOnly to hide the date section.

time-demo

Month Picker#

Month only picker is enabled by specifying view as month in addition to a suitable dateFormat.

month-picker-demo

Year Picker#

Year only picker is enabled by specifying view as year in addition to a suitable dateFormat.

year-picker-demo

Multiple Months#

Number of months to display is configured with the numberOfMonths property.

multiple-months-demo

Model Type#

The updateModelType property controls the data type of the value. When set to string it returns a string representation of the date, when set to date (default) it returns a Date object.

model-type-demo

Date Template#

Custom content can be placed inside date cells with the DatePicker.TableHeadCell component that takes a Date as a parameter.

date-template-demo

Arrow#

Use DatePicker.Arrow inside the popup to display an arrow pointing to the trigger element. Set sideOffset on DatePicker.Positioner for spacing.

arrow-demo

Inline#

WkSuMoTuWeThFrSa
512627282930311
12345678
29101112131415
316171819202122
423242526272829
5303112345
inline-demo

Inline Template#

Custom content can be placed inside date cells in inline mode with the DatePicker.TableHeadCell component that takes a Date as a parameter.

SuMoTuWeThFrSa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
SuMoTuWeThFrSa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
inline-template-demo

Float Label#

FloatLabel visually integrates a label with its form element. Visit FloatLabel documentation for more information.

float-label-demo

Ifta Label#

IftaLabel is used to create infield top aligned labels. Visit IftaLabel documentation for more information.

ifta-label-demo

Clear#

When DatePicker.Clear component is used, a clear trigger is added to reset the DatePicker.

clear-icon-demo

Sizes#

DatePicker provides small and large sizes as alternatives to the base.

sizes-demo

Fluid#

The fluid prop makes the component take up the full width of its container when set to true.

fluid-demo

Filled#

Specify the filled property to display the component with a higher visual emphasis than the default outlined style.

filled-demo

Disabled#

Use the disabled property to disable a datepicker.

disabled-demo

Invalid#

Specify the invalid property to display the component with a red border.

invalid-demo

API#

Sub-Components#

See Primitive API for DatePickerRoot, DatePickerInput, DatePickerPopup, DatePickerCalendar, DatePickerDay, DatePickerMonth, DatePickerYear, and all other sub-component documentation.

Hooks#

See Headless API for useDatePicker hook documentation.

Accessibility#

See DatePicker Primitive for WAI-ARIA compliance details and keyboard support.