## DateTimePicker Capture datetime from the user Category: Date Pickers ### DatePicker props `DateTimePicker` supports most of the `DatePicker` props, read through [DatePicker](/components/datepicker) documentation to learn about all component features that are not listed on this page. ### Simple Example ```python import dash_mantine_components as dmc from dash import Input, Output, html, callback, no_update component = html.Div( [ dmc.DateTimePicker( id="datetime-picker", label="Start Date and time", description="You can also provide a description", w=250, ), dmc.Space(h=10), dmc.Text(id="selected-datetime"), ] ) @callback(Output("selected-datetime", "children"), Input("datetime-picker", "value")) def update_output(d): return f"You have selected {d}" ``` ### Range Set `type="range"` to allow selecting a date and time range. In range mode, two time inputs are rendered for start and end times, and a range summary is displayed below: ```python import dash_mantine_components as dmc component = dmc.DateTimePicker( label="Pick date and time range", placeholder="Pick date and time range", type="range", ) ``` ### With Seconds ```python import dash_mantine_components as dmc component = dmc.DateTimePicker( label="Pick date and time", placeholder="Pick date and time", withSeconds=True, ) ``` ### Presets Use `presets` prop to add custom date presets. Presets are displayed next to the calendar: ```python from datetime import datetime, timedelta from dateutil.relativedelta import relativedelta import dash_mantine_components as dmc now = datetime.now() component = dmc.DateTimePicker( label="Pick date and time", placeholder="Pick date and time", presets=[ { "value": (now - timedelta(days=1)).isoformat(), "label": "Yesterday", }, { "value": now.isoformat(), "label": "Today", }, { "value": (now + timedelta(days=1)).isoformat(), "label": "Tomorrow", }, { "value": (now + relativedelta(months=1)).isoformat(), "label": "Next month", }, { "value": (now + relativedelta(years=1)).isoformat(), "label": "Next year", }, { "value": (now - relativedelta(months=1)).isoformat(), "label": "Last month", }, { "value": (now - relativedelta(years=1)).isoformat(), "label": "Last year", }, ] ) ``` ### TimePicker props You can pass props down to the underlying [TimePicker](//components/timepicker) component with `timePickerProps` prop. Example of enabling dropdown and setting 12h format for time picker: ```python from datetime import datetime import dash_mantine_components as dmc component = dmc.DateTimePicker( label="Pick date and time", placeholder="Pick Date and time", timePickerProps={ "withDropdown": True, "popoverProps": { "withinPortal": False }, "format": '12h', } ) ``` ### Value format Use `valueFormat` prop to change [dayjs format](https://day.js.org/docs/en/display/format) of value label. ```python import dash_mantine_components as dmc component = dmc.DateTimePicker( valueFormat="DD MMM YYYY hh:mm A", label="Pick date and time", placeholder="Pick date and time", ) ``` `valueFormat` also accepts a function that receives the value as a YYYY-MM-DD HH:mm:ss string and returns a custom formatted value. Use it when the formatting logic cannot be expressed with a dayjs format string: Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document. ```python import dash_mantine_components as dmc # Add dayjs as external script to make it available to the function # app = Dash(external_scripts=["https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.10.8/dayjs.min.js"]) component = dmc.DateTimePicker( label="Pick date and time", valueFormat={"function": "formatDateTimePicker"}, value="2026-10-14 14:45:00" ) ``` ```javascript var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {}; dmcfuncs.formatDateTimePicker = (date) => dayjs(date).format('dddd, MMMM D [at] h:mm A') ``` ### Disabled state ```python import dash_mantine_components as dmc component = dmc.DateTimePicker( disabled=True, label="Pick date and time (Disabled)", placeholder="Pick date and time", ) ``` ### Input props ### Clearable Set `clearable=True` prop to display clear button in the right section. Note that if you set `rightSection` prop, clear button will not be displayed. ```python from datetime import datetime import dash_mantine_components as dmc component = dmc.DateTimePicker( clearable=True, value="2025-01-01", label="Pick date and time (clearable)", placeholder="Pick Date and time", ) ``` ### Clear section mode The `clearSectionMode` prop determines how the `clear` button and `rightSection` are rendered: - 'both' (default) – render both the `clear` button and `rightSection` - 'rightSection' – render only the user-supplied `rightSection`, ignore `clear` button - 'clear' – render only the `clear` button, ignore `rightSection` ```python from datetime import date import dash_mantine_components as dmc from dash_iconify import DashIconify component = dmc.Stack([ dmc.DateTimePicker( label="clearSectionMode='both' (default)", placeholder="Pick a date and time", value="2027-01-01", clearable=True, rightSection=DashIconify(icon="tabler:chevron-down", width=16), clearSectionMode="both", ), dmc.DateTimePicker( label="clearSectionMode='rightSection'", placeholder="Pick a date and time", value="2027-01-01", clearable=True, rightSection=DashIconify(icon="tabler:chevron-down", width=16), clearSectionMode="rightSection", ), dmc.DateTimePicker( label="clearSectionMode='clear'", placeholder="Pick a date and time", value="2027-01-01", clearable=True, rightSection=DashIconify(icon="tabler:chevron-down", width=16), clearSectionMode="clear", ), ]) ``` ### Open picker in modal By default, `DateTimePicker` is rendered inside `Popover`. You can change that to `Modal` by setting `dropdownType="modal"` ```python import dash_mantine_components as dmc component = dmc.DateTimePicker( dropdownType="modal", label="Pick date and time (picker in modal)", placeholder="Pick date and time", ) ``` ### Native level select Set the `withNativeLevelSelect` prop to replace the calendar header level button with native `` elements default False. - withSeconds (boolean; optional): Determines whether seconds input should be rendered. - withSuccessStyles (boolean; optional): Determines whether the input should have green border when the `success` prop is set @,default,True. - withWeekNumbers (boolean; optional): Determines whether week numbers should be displayed, False by default. - wrapperProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional): Props passed down to the root element. - yearLabelFormat (string; optional): dayjs label format to display year label or a function that returns year label based on year value, defaults to "YYYY". - yearsListFormat (string; optional): dayjs format for years list, `'YYYY'` by default. - yearsSelectRange (list of 2 elements: [number, number]; optional): Year range for native level select, tuple of `[startYear, endYear]`. Defaults to `[currentYear - 100, currentYear + 50]` or values derived from `minDate`/`maxDate` if set.