# rememberDatePickerState

Common/AllAndroid/JVM

## Functions summary

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/material3/rememberDatePickerState.composable#rememberDatePickerState(java.time.LocalDate,java.time.YearMonth,kotlin.ranges.IntRange,androidx.compose.material3.DisplayMode,androidx.compose.material3.SelectableDates)( initialSelectedDate: https://developer.android.com/reference/java/time/LocalDate.html?, initialDisplayedMonth: https://developer.android.com/reference/java/time/YearMonth.html?, yearRange: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.ranges/-int-range/index.html, initialDisplayMode: https://developer.android.com/reference/kotlin/androidx/compose/material3/DisplayMode, selectableDates: https://developer.android.com/reference/kotlin/androidx/compose/material3/SelectableDates )` Creates a `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState` for a `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePicker.composable#DatePicker(androidx.compose.material3.DatePickerState,androidx.compose.ui.Modifier,androidx.compose.material3.DatePickerFormatter,androidx.compose.material3.DatePickerColors,kotlin.Function0,kotlin.Function0,kotlin.Boolean,androidx.compose.ui.focus.FocusRequester)` that is remembered across compositions. | android |
| `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable 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)( initialSelectedDateMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html?, initialDisplayedMonthMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html?, yearRange: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.ranges/-int-range/index.html, initialDisplayMode: https://developer.android.com/reference/kotlin/androidx/compose/material3/DisplayMode, selectableDates: https://developer.android.com/reference/kotlin/androidx/compose/material3/SelectableDates )` Creates a `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState` for a `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePicker.composable#DatePicker(androidx.compose.material3.DatePickerState,androidx.compose.ui.Modifier,androidx.compose.material3.DatePickerFormatter,androidx.compose.material3.DatePickerColors,kotlin.Function0,kotlin.Function0,kotlin.Boolean,androidx.compose.ui.focus.FocusRequester)` that is remembered across compositions. | Cmn |

## Functions

### rememberDatePickerState

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:rememberDatePickerState)

```
@RequiresApi(value = 26)
@Composable
fun rememberDatePickerState(
    initialSelectedDate: LocalDate?,
    initialDisplayedMonth: YearMonth? = initialSelectedDate?.let { YearMonth.from(it) },
    yearRange: IntRange = DatePickerDefaults.YearRange,
    initialDisplayMode: DisplayMode = DisplayMode.Picker,
    selectableDates: SelectableDates = DatePickerDefaults.AllDates
): DatePickerState
```

Creates a `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState` for a `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePicker.composable#DatePicker(androidx.compose.material3.DatePickerState,androidx.compose.ui.Modifier,androidx.compose.material3.DatePickerFormatter,androidx.compose.material3.DatePickerColors,kotlin.Function0,kotlin.Function0,kotlin.Boolean,androidx.compose.ui.focus.FocusRequester)` that is remembered across compositions.

Note: This composable uses `https://developer.android.com/reference/java/time/LocalDate.html` and `https://developer.android.com/reference/java/time/YearMonth.html`. For a lower-level composable that uses UTC milliseconds, see the other `https://developer.android.com/reference/kotlin/androidx/compose/material3/rememberDatePickerState.composable#rememberDatePickerState(java.time.LocalDate,java.time.YearMonth,kotlin.ranges.IntRange,androidx.compose.material3.DisplayMode,androidx.compose.material3.SelectableDates)` overload.

The initial values are converted to UTC milliseconds at the start of the day (midnight):

- `initialSelectedDate` is used to set `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#selectedDateMillis()`.

- `initialDisplayedMonth` is used to set `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState#displayedMonthMillis()`, based on the first day of that month.

To create a date picker state outside composition, see the `DatePickerState` function.

```kotlin
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.DatePicker
import androidx.compose.material3.DatePickerState
import androidx.compose.material3.Text
import androidx.compose.material3.getSelectedDate
import androidx.compose.material3.rememberDatePickerState
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

Column(
    modifier = Modifier.verticalScroll(rememberScrollState()),
    verticalArrangement = Arrangement.spacedBy(8.dp),
) {
    // Pre-select a date for April 15, 2023
    val datePickerState =
        rememberDatePickerState(initialSelectedDate = LocalDate.of(2023, 4, 15))
    DatePicker(state = datePickerState, modifier = Modifier.padding(16.dp))

    Text(
        "Selected date: ${datePickerState.getSelectedDate() ?: "no selection"}",
        modifier = Modifier.align(Alignment.CenterHorizontally),
    )
}
```

| Parameters |
|---|---|
| `initialSelectedDate: https://developer.android.com/reference/java/time/LocalDate.html?` | a `https://developer.android.com/reference/java/time/LocalDate.html` for an initial date selection. Provide a `null` to indicate no selection. |
| `initialDisplayedMonth: https://developer.android.com/reference/java/time/YearMonth.html? = initialSelectedDate?.let { YearMonth.from(it) }` | an optional `https://developer.android.com/reference/java/time/YearMonth.html` for an initial month that will be displayed to the user. By default, in case an `https://developer.android.com/reference/kotlin/androidx/compose/material3/package-summary#rememberDatePickerState(java.time.LocalDate,java.time.YearMonth,kotlin.ranges.IntRange,androidx.compose.material3.DisplayMode,androidx.compose.material3.SelectableDates)` is provided, the initial displayed month would be the month of the selected date. You may provide a different initial month, or `null` to display the current one. |
| `yearRange: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.ranges/-int-range/index.html = DatePickerDefaults.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 |
| `initialDisplayMode: https://developer.android.com/reference/kotlin/androidx/compose/material3/DisplayMode = DisplayMode.Picker` | an initial `https://developer.android.com/reference/kotlin/androidx/compose/material3/DisplayMode` that this state will hold |
| `selectableDates: https://developer.android.com/reference/kotlin/androidx/compose/material3/SelectableDates = DatePickerDefaults.AllDates` | 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. |

### rememberDatePickerState

Cmn 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+function:rememberDatePickerState)

```
@Composable
fun rememberDatePickerState(
    initialSelectedDateMillis: Long? = null,
    initialDisplayedMonthMillis: Long? = initialSelectedDateMillis,
    yearRange: IntRange = DatePickerDefaults.YearRange,
    initialDisplayMode: DisplayMode = DisplayMode.Picker,
    selectableDates: SelectableDates = DatePickerDefaults.AllDates
): DatePickerState
```

Creates a `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePickerState` for a `https://developer.android.com/reference/kotlin/androidx/compose/material3/DatePicker.composable#DatePicker(androidx.compose.material3.DatePickerState,androidx.compose.ui.Modifier,androidx.compose.material3.DatePickerFormatter,androidx.compose.material3.DatePickerColors,kotlin.Function0,kotlin.Function0,kotlin.Boolean,androidx.compose.ui.focus.FocusRequester)` that is remembered across compositions.

To create a date picker state outside composition, see the `DatePickerState` function.

| Parameters |
|---|---|
| `initialSelectedDateMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html? = null` | timestamp in *UTC* milliseconds from the epoch that represents an initial selection of a date. Provide a `null` to indicate no selection. |
| `initialDisplayedMonthMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html? = initialSelectedDateMillis` | timestamp in *UTC* milliseconds from the epoch that represents an initial selection of a month to be displayed to the user. By default, in case an `initialSelectedDateMillis` is provided, the initial displayed month would be the month of the selected date. Otherwise, in case `null` is provided, the displayed month would be the current one. |
| `yearRange: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.ranges/-int-range/index.html = DatePickerDefaults.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 |
| `initialDisplayMode: https://developer.android.com/reference/kotlin/androidx/compose/material3/DisplayMode = DisplayMode.Picker` | an initial `https://developer.android.com/reference/kotlin/androidx/compose/material3/DisplayMode` that this state will hold |
| `selectableDates: https://developer.android.com/reference/kotlin/androidx/compose/material3/SelectableDates = DatePickerDefaults.AllDates` | 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. |