DateTimeInput
Group: Input
Description
A DateTimeInput shows the browser's combined date and time
picker. The visitor picks a day and a clock time in one field, and
the result arrives at the route as a parameter with the field's
name. Use it for things that happen at a specific moment, like an
appointment or a deadline; when you only need one half, use
DateInput or TimeInput instead.
Syntax
DateTimeInput(name)
DateTimeInput(name, default_value)
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
name |
str |
required | The field's name, matching a parameter of the receiving route. |
default_value |
str or datetime.datetime |
empty | The pre-filled moment, written as "YYYY-MM-DDTHH:MM" (like "2026-07-27T14:30", with a capital T between the date and the time) or given as a datetime object. |
Like every component, DateTimeInput also accepts
styling and attribute keywords. The
HTML attributes it recognizes as keywords are min, max, step,
list, required, disabled, readonly, and autocomplete.
(list takes the id of an HTML <datalist>, not a Python list.)
Drafter turns any other keyword it does not recognize into a CSS
style;
Plain HTML attributes
explains that rule.
min and max limit the moments the picker offers. Write them in
the same "YYYY-MM-DDTHH:MM" form as the default, as in
DateTimeInput("moment", min="2026-08-01T09:00"). step is counted
in seconds. disabled=True and readonly=True both block changes,
and a disabled field's value is not sent to the route.
These limits apply to the picker only. Drafter does not ask the
browser to check the form when a button is clicked, so a moment typed
outside the range, or an empty field marked required=True, still
reaches the route. Check the value inside the route.
Examples
The route's parameter is annotated as datetime.datetime, so
Drafter converts the submitted text into a datetime object with
fields like .month, .day, and .hour:
from drafter import *
from dataclasses import dataclass
from datetime import datetime
@dataclass
class State:
appointment: str
@route
def index(state: State) -> Page:
return Page(state, [
Header("Grooming Appointment"),
"Babbage's next grooming: " + state.appointment + "\n",
"Reschedule to:",
DateTimeInput("moment", state.appointment),
"\n",
Button("Book it", "book")
])
@route
def book(state: State, moment: datetime) -> Page:
state.appointment = moment.isoformat(timespec="minutes")
return index(state)
start_server(State("2026-08-01T10:00"))
Notes
- Annotate the receiving parameter as
datetime.datetimeto get adatetimeobject, or asstrto get the raw"YYYY-MM-DDTHH:MM"text. - With a
datetimeannotation, leaving the field empty gives the route the current date and time. To tell an empty field apart from a chosen moment, annotate the parameter asdatetime | None, and an empty field givesNone. A parameter with a default value receives its default. With astrannotation, an empty field arrives as"". Blank values has the full rule. - The
Tin the middle of the value is part of the standard format;datetime.fromisoformatand Drafter's conversion both expect it. - There is no time zone in the value: it is whatever the visitor's computer considers local time.
Accessibility
Put a short label right before the field (the "Reschedule to:" text above, or a Label) so it is clear what moment is being chosen.