DatetimeRangePicker#

Open this notebook in Jupyterlite | Download this notebook from GitHub (right-click to download).


import datetime as dt

import panel as pn

pn.extension()

The DatetimeRangePicker widget allows selecting selecting a datetime value using a text box and the browser’s datetime-picking utility.

Discover more on using widgets to add interactivity to your applications in the how-to guides on interactivity. Alternatively, learn how to set up callbacks and (JS-)links between parameters or how to use them as part of declarative UIs with Param.

Parameters:#

For details on other options for customizing the component see the layout and styling how-to guides.

Core#

  • value (tuple): Tuple of upper and lower bounds of the selected range expressed as datetime types

  • start (date or datetime): Inclusive lower bound of the allowed date selection.

  • end (date or datetime): Inclusive upper bound of the allowed date selection.

  • disabled_dates (list): Dates to make unavailable for selection; others will be available

  • enabled_dates (list): Dates to make available for selection; others will be unavailable

  • enable_time: (boolean): Enable editing of the time in the widget, default is True

  • enable_seconds (boolean): Enable editing of seconds in the widget, default is True

  • military_time (boolean): Whether to display time in 24 hour format, default is True

Display#

  • disabled (boolean): Whether the widget is editable

  • name (str): The title of the widget

  • visible (boolean): Whether the widget is visible


DatetimeRangePicker uses a browser-dependent calendar widget to select the datetime:

datetime_range_picker = pn.widgets.DatetimeRangePicker(
    name='Datetime Range Picker', value=(dt.datetime(2021, 3, 2, 12, 10), dt.datetime(2021, 3, 2, 12, 22))
)

pn.Column(datetime_range_picker, height=400)

To ensure it is visible in a notebook we have placed it in a Column with a fixed height.

DatetimeRangePicker.value returns a tuple of datetime values that can be read out and set like other widgets:

datetime_range_picker.value
(datetime.datetime(2021, 3, 2, 12, 10), datetime.datetime(2021, 3, 2, 12, 22))

Controls#

The DatetimeRangePicker widget exposes a number of options which can be changed from both Python and Javascript. Try out the effect of these parameters interactively:

pn.Row(datetime_range_picker.controls(jslink=True), datetime_range_picker)

Open this notebook in Jupyterlite | Download this notebook from GitHub (right-click to download).