DateTimePicker

Capture datetime from the user

DatePicker props

DateTimePicker supports most of the DatePicker props. Read through the DatePicker documentation to learn about all component features that are not listed on this page.

DateTimePicker with uncontrolled forms

Set name to submit the selected date and time as YYYY-MM-DD HH:mm:ss, regardless of the display format:

import { DateTimePicker } from '@mantine/dates';

function Demo() {
  return (
    <form
      onSubmit={(event) => {
        event.preventDefault();
        const data = new FormData(event.currentTarget);
        console.log(data.get('meeting'));
      }}
    >
      <DateTimePicker
        name="meeting"
        label="Meeting"
        defaultValue="2025-05-12 14:30:00"
      />
      <button type="submit">Submit</button>
    </form>
  );
}

Usage

import { DateTimePicker } from '@mantine/dates';

function Demo() {
  return <DateTimePicker label="Pick date and time" placeholder="Pick date and time" />;
}

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:

import { DateTimePicker } from '@mantine/dates';

function Demo() {
  return (
    <DateTimePicker
      type="range"
      label="Pick dates and times range"
      placeholder="Pick dates and times range"
    />
  );
}

With seconds

import { DateTimePicker } from '@mantine/dates';

function Demo() {
  return <DateTimePicker withSeconds label="Pick date and time" placeholder="Pick date and time" />;
}

Presets

Use the presets prop to add custom date presets. Presets are displayed next to the calendar:

import dayjs from 'dayjs';
import { DateTimePicker } from '@mantine/dates';

function Demo() {
  return (
    <DateTimePicker
      label="Pick date and time"
      placeholder="Pick date and time"
      presets={[
        { value: dayjs().subtract(1, 'day').format('YYYY-MM-DD HH:mm:ss'), label: 'Yesterday' },
        { value: dayjs().format('YYYY-MM-DD HH:mm:ss'), label: 'Today' },
        { value: dayjs().add(1, 'day').format('YYYY-MM-DD HH:mm:ss'), label: 'Tomorrow' },
        { value: dayjs().add(1, 'month').format('YYYY-MM-DD HH:mm:ss'), label: 'Next month' },
        { value: dayjs().add(1, 'year').format('YYYY-MM-DD HH:mm:ss'), label: 'Next year' },
        {
          value: dayjs().subtract(1, 'month').format('YYYY-MM-DD HH:mm:ss'),
          label: 'Last month',
        },
        { value: dayjs().subtract(1, 'year').format('YYYY-MM-DD HH:mm:ss'), label: 'Last year' },
      ]}
    />
  );
}

TimePicker props

You can pass props down to the underlying TimePicker component with the timePickerProps prop. Example of enabling dropdown and setting 12h format for the time picker:

import { DateTimePicker } from '@mantine/dates';

function Demo() {
  return (
    <DateTimePicker
      label="Pick date and time"
      placeholder="Pick date and time"
      timePickerProps={{
        withDropdown: true,
        format: '12h',
      }}
    />
  );
}

Controlling with useDateTimePicker

DateTimePicker component supports the controller pattern. Use the useDateTimePicker hook to manage DateTimePicker state:

Dropdown closed, displayed month: none

import { useState } from 'react';
import { Button, Group, Stack, Text } from '@mantine/core';
import { DateTimePicker, useDateTimePicker } from '@mantine/dates';

function Demo() {
  const [value, setValue] = useState<string | null>('2024-06-15 10:30:00');
  const controller = useDateTimePicker();

  return (
    <Stack>
      <Group>
        <Button
          variant="default"
          onClick={() => {
            controller.openDropdown();
            controller.setLevel('year');
          }}
        >
          Pick a month
        </Button>
        <Button
          variant="default"
          onClick={() => {
            controller.openDropdown();
            controller.setDate(new Date());
          }}
        >
          Open at today
        </Button>
        <Button
          variant="default"
          onClick={() => {
            controller.openDropdown();
            controller.focusTime('hours');
          }}
        >
          Change time
        </Button>
      </Group>

      <DateTimePicker
        label="Pick date and time"
        placeholder="Pick date and time"
        value={value}
        onChange={setValue}
        controller={controller}
      />

      <Text size="sm" c="dimmed">
        Dropdown {controller.isDropdownOpened() ? 'opened' : 'closed'}, displayed{' '}
        {controller.getDisplayedLevel()}: {controller.getDisplayedDate() ?? 'none'}
      </Text>
    </Stack>
  );
}

useDateTimePicker has the actions and queries of useDatePickerInput – the dropdown actions together with the navigation actions of useCalendar – and the time actions of useInlineDateTimePicker:

import { useState } from 'react';
import { DateTimePicker, useDateTimePicker } from '@mantine/dates';

function Demo() {
  const [value, setValue] = useState<string | null>(null);
  const controller = useDateTimePicker({
    defaultLevel: 'month', // -> level the dropdown opens on
    defaultDate: '2024-06-15', // -> date the dropdown opens on when there is no value
    // dropdownOpened, defaultDropdownOpened, onDropdownOpenedChange -> dropdown state
    // date, onDateChange, level, onLevelChange -> same as on useCalendar
    // defaultTimeValue, time, onTimeChange, endTime, onEndTimeChange -> time inputs
  });

  // Dropdown actions
  controller.openDropdown();
  controller.closeDropdown();
  controller.toggleDropdown();

  // Navigation actions, same as useCalendar
  controller.setLevel('year');
  controller.setDate('2024-08-01');
  controller.next();
  controller.previous();

  // Time actions
  controller.setTime('09:00'); // -> sets the time inputs and the time of the value
  controller.focusTime('hours'); // -> focuses a field, also right after openDropdown
  controller.setEndTime('18:00'); // -> end time with type="range"
  controller.focusEndTime('minutes');

  // Queries
  controller.isDropdownOpened(); // -> true | false
  controller.getDate(); // -> displayed date
  controller.getLevel(); // -> 'month' | 'year' | 'decade'
  controller.getDisplayedDate(); // -> the date the dropdown displays
  controller.getDisplayedLevel(); // -> level clamped to minLevel/maxLevel
  controller.getTime(); // -> time of the time input, also before a date is picked
  controller.getEndTime(); // -> time of the end time input with type="range"

  return (
    <DateTimePicker value={value} onChange={setValue} controller={controller} />
  );
}

The controller does not own the selected value – keep using value/onChange (or your form library) for it. It owns what the value cannot express: the time entered before a date is picked and the end time of an incomplete range. setTime updates the time of the value when it has a date. When the dropdown is closed, the time set with setTime is shown and applied to the value the next time it opens. When the controller prop is set, the date, defaultDate, onDateChange, level, defaultLevel, onLevelChange and defaultTimeValue props are ignored – pass them to useDateTimePicker instead.

Every time the dropdown opens, it starts fresh: the displayed date is reset to the selected value (or to defaultDate when there is no value), the level is reset to defaultLevel, and the time inputs show the time of the value, discarding an incomplete time or a time typed before a date was picked. To open on a different level, date or time, call setLevel, setDate or setTime right after openDropdown, as the demo above does. A controlled date, level or time is not reset.

openDropdown does nothing while the input is disabled or readOnly. closeDropdown works the same way as when the user dismisses the dropdown: with type="range", a range with only the first date picked is cleared, the value is clamped to minDate/maxDate and onDropdownClose is called. The time inputs are driven through the DateTimePicker controller, so timePickerProps does not accept a controller. When the controller prop is set, popoverProps.opened and popoverProps.onChange are ignored – pass dropdownOpened and onDropdownOpenedChange to useDateTimePicker instead. Without a controller, popoverProps={{ opened, onChange }} controls the dropdown in every dropdown type (popover, modal and drawer).

The controller is typed as DateTimePickerController and its options as DateTimePickerControllerOptions, both exported from @mantine/dates.

Value format

Use the valueFormat prop to change the dayjs format of the value label:

import { DateTimePicker } from '@mantine/dates';

function Demo() {
  return (
    <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:

import dayjs from 'dayjs';
import { DateTimePicker } from '@mantine/dates';

function Demo() {
  return (
    <DateTimePicker
      valueFormat={(date) => dayjs(date).format('dddd, MMMM D [at] h:mm A')}
      defaultValue="2024-04-11 14:45:00"
      label="Pick date and time"
      placeholder="Pick date and time"
    />
  );
}

Disabled state

import { DateTimePicker } from '@mantine/dates';

function Demo() {
  return <DateTimePicker label="Disabled" placeholder="Pick date and time" disabled />;
}

Input props

DateTimePicker component supports Input and Input.Wrapper component features and all button element props. The DateTimePicker documentation does not include all features supported by the component – see the Input documentation to learn about all available features.

Input description

Variant
Size
Radius
import { DateTimePicker } from '@mantine/dates';

function Demo() {
  return (
    <DateTimePicker
      label="Input label"
      description="Input description"
      placeholder="Input placeholder"
    />
  );
}

Clearable

Set the clearable prop to display a clear button in the right section. Note that if you set the rightSection prop, the clear button will not be displayed.

import dayjs from 'dayjs';
import { DateTimePicker } from '@mantine/dates';

function Demo() {
  return (
    <DateTimePicker
      clearable
      defaultValue={dayjs().format('YYYY-MM-DD')}
      label="Pick date and time"
      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
import { CaretDownIcon } from '@phosphor-icons/react';
import { Stack } from '@mantine/core';
import { DateTimePicker } from '@mantine/dates';

function Demo() {
  return (
    <Stack>
      <DateTimePicker
        label="clearSectionMode='both' (default)"
        placeholder="Pick date and time"
        defaultValue={new Date()}
        clearable
        rightSection={<CaretDownIcon size={16} />}
        clearSectionMode="both"
      />

      <DateTimePicker
        label="clearSectionMode='rightSection'"
        placeholder="Pick date and time"
        defaultValue={new Date()}
        clearable
        rightSection={<CaretDownIcon size={16} />}
        clearSectionMode="rightSection"
      />

      <DateTimePicker
        label="clearSectionMode='clear'"
        placeholder="Pick date and time"
        defaultValue={new Date()}
        clearable
        rightSection={<CaretDownIcon size={16} />}
        clearSectionMode="clear"
      />
    </Stack>
  );
}

Dropdown type

The dropdown opens in a bottom Drawer below theme.breakpoints.sm and in a Popover above. Set dropdownType to 'popover', 'modal', 'drawer' or an object with breakpoints:

import { Stack } from '@mantine/core';
import { DateTimePicker } from '@mantine/dates';

function Demo() {
  return (
    <Stack>
      <DateTimePicker dropdownType="drawer" label="Drawer" placeholder="Pick date and time" />
      <DateTimePicker dropdownType="modal" label="Modal" placeholder="Pick date and time" />
      <DateTimePicker dropdownType="popover" label="Popover" placeholder="Pick date and time" />
      <DateTimePicker
        dropdownType={{ base: 'drawer', 600: 'popover' }}
        label="Drawer below 600px, popover above"
        placeholder="Pick date and time"
      />
    </Stack>
  );
}

Object keys can be theme.breakpoints keys or custom values in px, for example, { base: 'drawer', 600: 'popover' }. Use popoverProps, modalProps and drawerProps to pass props down to the underlying component. If the viewport crosses a breakpoint while the dropdown is open, the dropdown switches to the other type and a selection that was not applied yet is discarded.

Submit button

In drawer and modal dropdowns, the value is applied only when the submit button is pressed, and closing the dropdown discards the selection. Set applyOnSubmit={false} to apply the value on selection:

import { DateTimePicker } from '@mantine/dates';

function Demo() {
  return (
    <DateTimePicker
      dropdownType="drawer"
      applyOnSubmit={false}
      label="Applied on selection"
      placeholder="Pick date and time"
    />
  );
}
  • The submit button is rendered in every dropdown type
  • The label is Save by default – change it with the submitButtonLabel prop or the submitButtonLabel setting of DatesProvider
  • submitButtonProps are passed down to the Button
  • With type="range", the button is disabled until both dates are selected

Mobile time input

In the drawer dropdown, time is entered with a native <input type="time" /> (TimeInput) instead of TimePicker. With withSeconds (as a prop or in timePickerProps), TimePicker is used in all dropdown types. disabled, readOnly, aria-label, aria-describedby, id, name, className and style from timePickerProps (and from endTimePickerProps for the end time input) are applied to the native input as well.

Native level select

import { DateTimePicker } from '@mantine/dates';

function Demo() {
  return (
    <DateTimePicker
      label="Pick date and time"
      placeholder="Pick date and time"
      withNativeLevelSelect
    />
  );
}

Get element ref

import { useRef } from 'react';
import { DateTimePicker } from '@mantine/dates';

function Demo() {
  const ref = useRef<HTMLButtonElement>(null);
  return <DateTimePicker ref={ref} />;
}

Accessibility

If DateTimePicker is used without the label prop, it will not be announced properly by screen readers:

import { DateTimePicker } from '@mantine/core';

// Inaccessible input – screen reader will not announce it properly
function Demo() {
  return <DateTimePicker />;
}

Set aria-label to make the input accessible. In this case the label will not be visible, but screen readers will announce it:

import { DateTimePicker } from '@mantine/core';

// Accessible input – it has aria-label
function Demo() {
  return <DateTimePicker aria-label="My input" />;
}

If the label prop is set, the input will be accessible and it is not required to set aria-label:

import { DateTimePicker } from '@mantine/core';

// Accessible input – it has associated label element
function Demo() {
  return <DateTimePicker label="My input" />;
}