# DatePickerState

Artifact: [androidx.compose.material3:material3](https://developer.android.com/jetpack/androidx/releases/compose-material3) [View Source](https://cs.android.com/search?q=file:androidx/compose/material3/DatePicker.kt+class:androidx.compose.material3.DatePickerState) Common/AllAndroid/JVM
- Cmn

  ```
  interface DatePickerState
  ```

*** ** * ** ***

A state object that can be hoisted to observe the date picker state. See `https://developer.android.com/reference/kotlin/androidx/compose/material3/rememberDatePickerState.composable#rememberDatePickerState(kotlin.Long,kotlin.Long,kotlin.ranges.IntRange,androidx.compose.material3.DisplayMode,androidx.compose.material3.SelectableDates)`.

## Summary

| ### Public properties |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/material3/DisplayMode` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#displayMode()` A `https://developer.android.com/reference/kotlin/androidx/compose/material3/DisplayMode` that represents the current UI mode (i.e. picker or input). | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#displayedMonthMillis()` A timestamp that represents the currently displayed month *start* date in *UTC* milliseconds from the epoch. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/material3/CalendarLocale` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#locale()` A locale that will be used when formatting dates, determining the input format, week-days, and more. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/material3/SelectableDates` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#selectableDates()` A `https://developer.android.com/reference/kotlin/androidx/compose/material3/SelectableDates` that is consulted to check if a date is allowed. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html?` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#selectedDateMillis()` A timestamp that represents the selected date *start* of the day in *UTC* milliseconds from the epoch. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.ranges/-int-range/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#yearRange()` An `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.ranges/-int-range/index.html` that holds the year range that the date picker will be limited to. | Cmn |

| ### Extension functions |
|---|---|---|
| `https://developer.android.com/reference/java/time/YearMonth.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState.https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#(androidx.compose.material3.DatePickerState).getDisplayedMonth()()` Returns a `https://developer.android.com/reference/java/time/YearMonth.html` representation of the displayed month in this `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState`. | android |
| `https://developer.android.com/reference/java/time/LocalDate.html?` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState.https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#(androidx.compose.material3.DatePickerState).getSelectedDate()()` Returns a `https://developer.android.com/reference/java/time/LocalDate.html` representation of the selected date in this `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState`, or `null` in case there is no selection. | android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState.https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#(androidx.compose.material3.DatePickerState).setDisplayedMonth(java.time.YearMonth)(yearMonth: https://developer.android.com/reference/java/time/YearMonth.html)` Sets the `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#displayedMonthMillis()` based on a given `https://developer.android.com/reference/java/time/YearMonth.html`. | android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState.https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#(androidx.compose.material3.DatePickerState).setSelectedDate(java.time.LocalDate)(date: https://developer.android.com/reference/java/time/LocalDate.html?)` Sets the `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#selectedDateMillis()` based on a given `https://developer.android.com/reference/java/time/LocalDate.html`. | android |

## Public properties

### displayMode

Cmn

```
var displayMode: DisplayMode
```

A `https://developer.android.com/reference/kotlin/androidx/compose/material3/DisplayMode` that represents the current UI mode (i.e. picker or input).

### displayedMonthMillis

Cmn

```
var displayedMonthMillis: Long
```

A timestamp that represents the currently displayed month *start* date in *UTC* milliseconds from the epoch.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | in case the value is set with a timestamp that does not fall within the `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#yearRange()`. |

### locale

Cmn

```
val locale: CalendarLocale
```

A locale that will be used when formatting dates, determining the input format, week-days, and more.

### selectableDates

Cmn

```
val selectableDates: SelectableDates
```

A `https://developer.android.com/reference/kotlin/androidx/compose/material3/SelectableDates` that is consulted to check if a date is allowed.

In case a date is not allowed to be selected, it will appear disabled in the UI.

### selectedDateMillis

Cmn

```
var selectedDateMillis: Long?
```

A timestamp that represents the selected date *start* of the day in *UTC* milliseconds from the epoch.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | in case the value is set with a timestamp that does not fall within the `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#yearRange()`. |

### yearRange

Cmn

```
val yearRange: IntRange
```

An `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.ranges/-int-range/index.html` that holds the year range that the date picker will be limited to.

## Extension functions

### DatePickerState.getDisplayedMonth

android Artifact: [androidx.compose.material3:material3](https://developer.android.com/jetpack/androidx/releases/compose-material3) [View Source](https://cs.android.com/search?q=file:androidx/compose/material3/DatePicker.jvmAndAndroid.kt+function:getDisplayedMonth)

```
@RequiresApi(value = 26)
fun DatePickerState.getDisplayedMonth(): YearMonth
```

Returns a `https://developer.android.com/reference/java/time/YearMonth.html` representation of the displayed month in this `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState`. The returned `https://developer.android.com/reference/java/time/YearMonth.html` is based on the `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#displayedMonthMillis()`, which represents midnight of the first day of the displayed month in UTC milliseconds from the epoch.

| Returns |
|---|---|
| `https://developer.android.com/reference/java/time/YearMonth.html` | The displayed `https://developer.android.com/reference/java/time/YearMonth.html`. |

### DatePickerState.getSelectedDate

android Artifact: [androidx.compose.material3:material3](https://developer.android.com/jetpack/androidx/releases/compose-material3) [View Source](https://cs.android.com/search?q=file:androidx/compose/material3/DatePicker.jvmAndAndroid.kt+function:getSelectedDate)

```
@RequiresApi(value = 26)
fun DatePickerState.getSelectedDate(): LocalDate?
```

Returns a `https://developer.android.com/reference/java/time/LocalDate.html` representation of the selected date in this `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState`, or `null` in case there is no selection.

| Returns |
|---|---|
| `https://developer.android.com/reference/java/time/LocalDate.html?` | The selected `https://developer.android.com/reference/java/time/LocalDate.html`, or `null` if there is no selection. |

### DatePickerState.setDisplayedMonth

android Artifact: [androidx.compose.material3:material3](https://developer.android.com/jetpack/androidx/releases/compose-material3) [View Source](https://cs.android.com/search?q=file:androidx/compose/material3/DatePicker.jvmAndAndroid.kt+function:setDisplayedMonth)

```
@RequiresApi(value = 26)
fun DatePickerState.setDisplayedMonth(yearMonth: YearMonth): Unit
```

Sets the `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#displayedMonthMillis()` based on a given `https://developer.android.com/reference/java/time/YearMonth.html`.

Converts the `https://developer.android.com/reference/java/time/YearMonth.html` to the start of the first day of that month (midnight) in UTC and apply it to the `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState` `displayedMonthMillis`.

| Parameters |
|---|---|
| `yearMonth: https://developer.android.com/reference/java/time/YearMonth.html` | The `https://developer.android.com/reference/java/time/YearMonth.html` to display. |

### DatePickerState.setSelectedDate

android Artifact: [androidx.compose.material3:material3](https://developer.android.com/jetpack/androidx/releases/compose-material3) [View Source](https://cs.android.com/search?q=file:androidx/compose/material3/DatePicker.jvmAndAndroid.kt+function:setSelectedDate)

```
@RequiresApi(value = 26)
fun DatePickerState.setSelectedDate(date: LocalDate?): Unit
```

Sets the `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#selectedDateMillis()` based on a given `https://developer.android.com/reference/java/time/LocalDate.html`.

Converts the `https://developer.android.com/reference/java/time/LocalDate.html` to the start of the day (midnight) in UTC and apply it to the `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState` `selectedDateMillis`. Setting `null` clears the selection.

| Parameters |
|---|---|
| `date: https://developer.android.com/reference/java/time/LocalDate.html?` | The `https://developer.android.com/reference/java/time/LocalDate.html` to select, or `null` to clear the selection. |