Date picker

Lets people choose a date or a range of dates, by calendar or by typing.

When to use

Use the modal date picker in a DatePickerDialog for a single date, and the date range picker for travel or booking style choices. People can switch between the calendar and text input.

Limit selectable dates with SelectableDates, for example to exclude past days.

Playground

The interactive page has a playground with live property controls for this component and generated code.

Examples

In a dialog

var open by rememberSaveable { mutableStateOf(false) }
val state = rememberDatePickerState()

Button(onClick = { open = true }) { Text("Pick a date") }

if (open) {
    DatePickerDialog(
        onDismissRequest = { open = false },
        confirmButton = { TextButton(onClick = { open = false }) { Text("OK") } },
        dismissButton = { TextButton(onClick = { open = false }) { Text("Cancel") } },
    ) {
        DatePicker(state = state)
    }
}

Parameters

NameTypeDefaultDescription
stateDatePickerStaterememberDatePickerState(). Holds selectedDateMillis and the display mode.
initialDisplayModeDisplayModePickerStart in calendar or input mode.
selectableDatesSelectableDatesAllDatesRestricts selectable days and years.
yearRangeIntRangeDatePickerDefaults.YearRangeSelectable years.

Guidelines

Do:

Don't:

Accessibility

Related components