Skip to main content

Date Time Input

DateTimeInput combines a calendar and clock picker. It returns the full timestamp the user chose.

Signature

dt := ui.DateTimeInput(label string, opts ...datetimeinput.Option) *time.Time

dt is nil until the user selects a value.

Option helpers

HelperPurposeDefault
datetimeinput.WithPlaceholder("YYYY‑MM‑DD HH:mm")Placeholder when empty""
datetimeinput.WithDefaultValue(time.Now())Pre‑fill on first rendernil
datetimeinput.WithRequired(true)Require a value inside a Formfalse
datetimeinput.WithDisabled(true)Read‑only fieldfalse
datetimeinput.WithFormat("MM/DD/YYYY HH:mm")Display / parse format (Moment‑style tokens)"YYYY/MM/DD HH:MM:SS"
datetimeinput.WithMaxValue(t)Latest selectable timestampnil
datetimeinput.WithMinValue(t)Earliest selectable timestampnil
datetimeinput.WithLocation(loc)Time‑zone for parsing & formattingtime.Local

Behaviour

  • State type – stored as time.Time. Changing WithFormat only affects rendering, not stored value.
  • ValidationRequired, Min/MaxValue enforce constraints client‑side before rerun.
  • Time‑zone – all conversions use the provided Location; this matters when comparing dates across zones.

Examples

Basic input

ev := ui.DateTimeInput("Event time")
if ev != nil {
fmt.Println("selected:", ev.Format(time.RFC3339))
}

Custom format + placeholder

ui.DateTimeInput("Start",
datetimeinput.WithPlaceholder("MM/DD/YYYY HH:mm"),
datetimeinput.WithFormat("MM/DD/YYYY HH:mm"),
)

Range‑restricted picker

now := time.Now()
ui.DateTimeInput("Deadline",
datetimeinput.WithMinValue(now),
datetimeinput.WithMaxValue(now.Add(24*time.Hour)),
)

Pre‑selected, disabled

ui.DateTimeInput("Created",
datetimeinput.WithDefaultValue(time.Now()),
datetimeinput.WithDisabled(true),
)