## DatePicker Inline date, multiple dates and dates range picker Category: Date Pickers > Looking for a date picker with an input field and a dropdown calendar? Try `DateInput` or `DatePickerInput`. ### Simple Example This is a simple example of `DatePicker` with a callback. Use a string in the format 'YYYY-MM-DD'. ```python import dash_mantine_components as dmc from dash import Input, Output, html, callback component = dmc.Stack([ dmc.DatePicker(id="date-picker"), dmc.Text(id="selected-date-picker", mt=10), ], align="center") @callback( Output("selected-date-picker", "children"), Input("date-picker", "value") ) def update_output(d): return f"You selected {d}" ``` ### Allow deselect Set `allowDeselect` to allow user to deselect current selected date by clicking on it. `allowDeselect` is disregarded when `type` prop is `range` or `multiple`. When date is deselected the value is None. ```python import dash_mantine_components as dmc from dash import Input, Output, html, callback component = dmc.Stack([ dmc.DatePicker( id="date-picker-allow-deselect", allowDeselect=True ), dmc.Text(id="date-picker-out-allow-deselect"), ], align="center") @callback( Output("date-picker-out-allow-deselect", "children"), Input("date-picker-allow-deselect", "value") ) def update_output(d): return f"You selected {d}" ``` ### Multiple dates Set `type="multiple"` to allow user to pick multiple dates. Note that value must be a list. ```python import dash_mantine_components as dmc from dash import Input, Output, html, callback component = dmc.Stack([ dmc.DatePicker( id="date-picker-multiple", value=[], type="multiple" ), dmc.Text(id="date-picker-out-multiple"), ], align="center") @callback( Output("date-picker-out-multiple", "children"), Input("date-picker-multiple", "value") ) def update_output(d): return f"You selected {str(d)}" ``` ### Dates range Set `type="range"` to allow user to pick dates range. Note that value must be a list. ```python import dash_mantine_components as dmc from dash import Input, Output, html, callback component = dmc.Stack([ dmc.DatePicker( id="date-picker-range", value=[], type="range" ), dmc.Text(id="date-picker-out-range"), ], align="center") @callback( Output("date-picker-out-range", "children"), Input("date-picker-range", "value") ) def update_output(d): return f"You selected {str(d)}" ``` ### Single date in range By default, it is not allowed to select single date as range – when user clicks the same date second time it is deselected. To change this behavior set `allowSingleDateInRange=True` prop. `allowSingleDateInRange` is ignored when type prop is not range. ```python import dash_mantine_components as dmc from dash import Input, Output, html, callback component = dmc.Stack([ dmc.DatePicker( id="date-picker-range-s", value=[], type="range", allowSingleDateInRange=True ), dmc.Text(id="date-picker-out-range-s"), ], align="center") @callback( Output("date-picker-out-range-s", "children"), Input("date-picker-range-s", "value") ) def update_output(d): return f"You selected {str(d)}" ``` ### Presets Use `presets` prop to add custom date presets. Presets are displayed next to the calendar: ```python from datetime import date, timedelta from dateutil.relativedelta import relativedelta import dash_mantine_components as dmc today = date.today() component = dmc.Center( dmc.DatePicker( presets=[ { "value": (today - timedelta(days=1)).isoformat(), "label": "Yesterday", }, { "value": today.isoformat(), "label": "Today", }, { "value": (today + timedelta(days=1)).isoformat(), "label": "Tomorrow", }, { "value": (today + relativedelta(months=1)).isoformat(), "label": "Next month", }, { "value": (today + relativedelta(years=1)).isoformat(), "label": "Next year", }, { "value": (today - relativedelta(months=1)).isoformat(), "label": "Last month", }, { "value": (today - relativedelta(years=1)).isoformat(), "label": "Last year", }, ] ) ) ``` To use `presets` with `type="range"`, define value a tuple of two dates: ```python from datetime import date, timedelta from dateutil.relativedelta import relativedelta import dash_mantine_components as dmc today = date.today() component = dmc.Center( dmc.DatePicker( type="range", presets=[ { "value": [ (today - timedelta(days=2)).isoformat(), today.isoformat(), ], "label": "Last two days", }, { "value": [ (today - timedelta(days=7)).isoformat(), today.isoformat(), ], "label": "Last 7 days", }, { "value": [ today.replace(day=1).isoformat(), today.isoformat(), ], "label": "This month", }, { "value": [ (today - relativedelta(months=1)).replace(day=1).isoformat(), (today.replace(day=1) - timedelta(days=1)).isoformat(), ], "label": "Last month", }, { "value": [ date(today.year - 1, 1, 1).isoformat(), date(today.year - 1, 12, 31).isoformat(), ], "label": "Last year", }, ], ) ) ``` ### Default date Use `defaultDate` prop to set date value that will be used to determine which year should be displayed initially. For example to display 2015 February month set `defaultDate="2015-02-01"`. If value is not specified, then defaultDate will use today's date. Day, minutes and seconds are ignored in provided date, only year and month data is used – you can specify any date value. ```python import dash_mantine_components as dmc component = dmc.Center( dmc.DatePicker(defaultDate="2015-02-01") ) ``` ### Level Set `level` prop to configure initial level that will be displayed: ```python import dash_mantine_components as dmc component = dmc.Group([ dmc.DatePicker(level="decade"), dmc.DatePicker(level="year") ], justify="center") ``` ### Full width Set the `fullWidth` prop to make the date picker stretch to fill 100% of its parent container width: ```python import dash_mantine_components as dmc component = dmc.Center( dmc.DatePicker(fullWidth=True) ) ``` ### Hide outside dates Set `hideOutsideDates=True` to remove all dates that do not belong to the current month: ```python import dash_mantine_components as dmc component = dmc.Center( dmc.DatePicker(hideOutsideDates=True) ) ``` ### Display week numbers Set `withWeekNumbers=True` to display week numbers: ```python import dash_mantine_components as dmc component = dmc.Center( dmc.DatePicker(withWeekNumbers=True) ) ``` ### First day of week Set `firstDayOfWeek` prop to configure first day of week. The prop accepts number from 0 to 6, where 0 is Sunday and 6 is Saturday. Default value is 1 – Monday. You can also configure this option for all components with `DatesProvider`. ```python import dash_mantine_components as dmc component = dmc.Group([ dmc.DatePicker(firstDayOfWeek=0), dmc.DatePicker(firstDayOfWeek=6) ], justify="center", gap="xl") ``` ### Hide weekdays Set `hideWeekdays=True` to hide weekdays names: ```python import dash_mantine_components as dmc component = dmc.Center( dmc.DatePicker(hideWeekdays=True) ) ``` ### Weekend days Use `weekendDays` prop to configure weekend days. The prop accepts an array of numbers from 0 to 6, where 0 is Sunday and 6 is Saturday. Default value is `[0, 6]` – Saturday and Sunday. You can also configure this option for all components with DatesProvider. ```python import dash_mantine_components as dmc component = dmc.Center( dmc.DatePicker(weekendDays=[1,2]) ) ``` ### Min and max date Set `minDate` and `maxDate` props to define min and max dates. If previous/next page is not available then corresponding control will be disabled. ```python import dash_mantine_components as dmc component = dmc.Center( dmc.DatePicker( minDate="2025-05-10", maxDate = "2025-05-25" ) ) ``` ### Change header controls order Use `headerControlsOrder` prop to change order of header controls. The prop accepts a list of 'next' | 'previous' | 'level'. Note that each control can be used only once in the list. ```python import dash_mantine_components as dmc component = dmc.DatePicker( value="2025-02-01", headerControlsOrder = ['level', 'previous', 'next'], styles = { "calendarHeaderLevel": { "justifyContent": 'flex-start', "paddingInlineStart": 8, }, } ) ``` ### Add props to year and month control Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document. You can add props to year, month and day controls with `getYearControlProps`, `getMonthControlProps` and `getDayProps` functions. All functions accept date as single argument, props returned from the function will be added to year/month/day control. For example, it can be used to disable specific control or add styles: ```python import dash_mantine_components as dmc # Adding 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.DatePicker( defaultDate="2025-06-01", getDayProps={"function": "highlightFriday13"}, getYearControlProps={"function": "yearControlProps"}, getMonthControlProps={"function": "monthControlProps"}, my="lg" ) ``` ```javascript var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {}; // dayjs is loaded globally via Dash external_scripts. // For details, see DatesProvider docs: https://www.dash-mantine-components.com/components/datesprovider var dayjs = window.dayjs; dmcfuncs.highlightFriday13 = function (dateStr) { const d = dayjs(dateStr); if (d.day() === 5 && d.date() === 13) { return { style: { backgroundColor: 'var(--mantine-color-red-filled)', color: 'var(--mantine-color-white)', }, }; } return {}; }; dmcfuncs.yearControlProps = function (dateStr) { const d = dayjs(dateStr); const currentYear = new Date().getFullYear(); if (d.year() === currentYear) { return { style: { color: 'var(--mantine-color-blue-filled)', fontWeight: 700, }, }; } if (d.year() === currentYear + 1) { return { disabled: true }; } return {}; }; dmcfuncs.monthControlProps = function (dateStr) { const d = dayjs(dateStr); if (d.month() === 1) { return { style: { color: 'var(--mantine-color-blue-filled)', fontWeight: 700, }, }; } if (d.month() === 5) { return { disabled: true }; } return {}; }; ``` ### Render day function Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document. You can customize day rendering with renderDay prop. For example, it can be used to add `Indicator` to certain days. ```python import dash_mantine_components as dmc # Adding 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.DatePicker( id="custom-day-render", renderDay={"function": "highlightSixteenthWithDot"} ) ``` ```javascript var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {}; var dmc = window.dash_mantine_components; var dayjs = window.dayjs; dmcfuncs.highlightSixteenthWithDot = function (dateStr) { const day = dayjs(dateStr).date(); return React.createElement( dmc.Indicator, { size: 9, color: "red", offset: -5, disabled: day !== 16, // displays indicator only on the the 16th doy of the month }, React.createElement("div", null, day) ); }; ``` ### Disabled dates #### Example 1: A List of dates Use the `disabledDates` prop to pass a list of specific dates to disable. Dates must be strings in the YYYY-MM-DD format. ```python import dash_mantine_components as dmc component = dmc.Center( dmc.DatePicker( value="2024-11-05", defaultDate="2024-11-01", disabledDates=["2024-11-06", "2024-11-07", "2024-11-08"], m="lg" ) ) ``` #### Example 2: A Function Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document. The `disabledDates` prop accepts a function that receives a date string (in 'YYYY-MM-DD' format) and returns true if the date should be disabled. This example uses [dayjs](https://day.js.org/) to simplify working with dates in JavaScript. To use `dayjs` in your Dash app, load it as an external script: ```python app = Dash(external_scripts=[ "https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.10.8/dayjs.min.js" ]) ``` Here, `dayjs(dateStr).day()` is used to check the day of the week. This is more reliable than manually parsing the date string and helps avoid common timezone issues. The example below disables all dates except Fridays: ```python import dash_mantine_components as dmc # makes dayjs available #app = Dash(exteral_scripts=["https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.10.8/dayjs.min.js"]) component = dmc.Center( dmc.DatePicker( value="2024-11-08", defaultDate="2024-11-01", disabledDates={"function": "excludeDate"}, m="lg" ) ) ``` ```javascript var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {}; dmcfuncs.excludeDate = function(dateStr) { const date = dayjs(dateStr, "YYYY-MM-DD"); return date.isValid() && date.day() !== 5; } ``` ### Number of columns Set `numberOfColumns` prop to define number of pickers that will be rendered side by side: ```python import dash_mantine_components as dmc component = dmc.Center( dmc.DatePicker(numberOfColumns=2) ) ``` ### Max level ```python import dash_mantine_components as dmc component = dmc.Group([ dmc.DatePicker(maxLevel="year"), dmc.DatePicker(maxLevel="month") ], justify="center", gap="xl") ``` ### Change year and months controls format Use `yearsListFormat` and `monthsListFormat` props to change [dayjs](https://day.js.org/docs/en/display/format) format of year/month controls: ```python import dash_mantine_components as dmc component = dmc.Center( dmc.DatePicker(monthsListFormat="MM", yearsListFormat="YY") ) ``` ### Change label format Use `decadeLabelFormat`, `yearLabelFormat` and `monthLabelFormat` props to change [dayjs](https://day.js.org/docs/en/display/format) format of decade/year label: ```python import dash_mantine_components as dmc component = dmc.Center( dmc.DatePicker( decadeLabelFormat="YY", yearLabelFormat="YYYY [year]", monthLabelFormat="MM/YY", ) ) ``` ### Localization For information on setting locale, have a look at the [DatesProvider](/components/datesprovider) component. ### Native level select Set the `withNativeLevelSelect` prop to replace the calendar header level button with native `` elements default False. - withWeekNumbers (boolean; optional): Determines whether week numbers should be displayed, False by default. - 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.