Skip to main content

Date Format

Set how the date and date-time pickers across Catalyst show their values. Formats are Ruby strftime strings β€” the same notation used for the format: option on columns and fields β€” and default to Dec 13, 2026 / Dec 13, 2026, 2:29 PM style output.

Quick example​

config/initializers/catalyst.rb
Catalyst.configure do |config|
config.display_date_format = "%d/%m/%Y" # 06/08/2026
config.display_datetime_format = "%b %-d, %Y %I:%M %p" # Aug 6, 2026 02:30 PM
end

Options​

OptionDefaultDescription
display_date_format"%b %-d, %Y"Format of date pickers.
display_datetime_format"%b %-d, %Y, %-I:%M %p"Format of date-time pickers (12-hour).

Date-time pickers always offer a 12-hour time control with an AM/PM toggle; use %I/%p (or %H for 24-hour) to match the displayed text. Date range filters show both dates in display_date_format, joined by to.

Supported directives​

DirectiveOutput
%Y / %y2026 / 26
%B / %b (%h)August / Aug
%A / %aThursday / Thu
%m / %-m08 / 8
%d / %-d / %e06 / 6 / 6
%H / %k14 / 14 (24-hour, %k space-pads)
%I / %l02 / 2 (12-hour)
%M05 (minutes)
%S00 (seconds)
%p / %PPM / pm
%%%
%F, %D, %R, %T, %r, %vCompound formats (%Y-%m-%d, %m/%d/%y, %H:%M, %H:%M:%S, %I:%M:%S %p, %e-%b-%Y)

The - and _ flags work on the numeric directives (%-d β†’ 6, %_d β†’ 6). Typed values are read back with the same format; ISO values (2026-08-06) are always accepted too.

The formats are exposed to JavaScript as window.catalystConfig.displayDateFormat and window.catalystConfig.displayDateTimeFormat. They only change what the picker shows: forms still submit ISO values (see below).

Submitted values​

Forms submit ISO values: YYYY-MM-DD for dates, YYYY-MM-DDTHH:MM for date-times (a UTC timestamp, YYYY-MM-DDTHH:MM:00Z, for fields with a timezone: option) and YYYY-MM-DD to YYYY-MM-DD for date range filters.

Setting the value from JavaScript​

Each picker renders two inputs: a visible text field (data-datepicker-target="input") that shows the formatted date and accepts typing, and a hidden input (data-datepicker-target="value") that carries the field's name and the submitted ISO value. The datepicker Stimulus controller keeps them in sync automatically β€” assigning .value on either input updates the other, the calendar's selection, and the clear button. No extra calls are needed:

app/javascript/prefill_dates.js
const wrapper = document.querySelector('[data-controller~="datepicker"]');

// via the hidden input β€” visible text and calendar selection update
wrapper.querySelector('[data-datepicker-target="value"]').value = "2026-11-23";

// or via the visible input β€” parsed like typed text (display format or ISO)
wrapper.querySelector('[data-datepicker-target="input"]').value =
"Nov 23, 2026";

The two writes differ in notification, mirroring user behaviour:

  • Hidden input β€” syncs silently, like the controller's own refresh(). Dispatch change on it yourself if listeners (like date filters) should react:

    const hidden = wrapper.querySelector('[data-datepicker-target="value"]');
    hidden.value = "2026-11-23";
    hidden.dispatchEvent(new Event("change", { bubbles: true }));
  • Visible input β€” commits like typed input: the text is parsed (unparseable text reverts to the last valid value), the hidden input syncs, and change fires on it.

To clear a picker from JavaScript, assign "" β€” or call controller.clear() where controller is window.Stimulus.getControllerForElementAndIdentifier(wrapper, "datepicker") (this.application.… inside another Stimulus controller).

Reacting to user changes​

The other direction works through the hidden input too: when the user picks a date from the calendar or finishes typing, the controller writes the committed ISO value into it and dispatches change. Listen for change on the hidden input β€” it bubbles, so a delegated listener on a parent form works as well:

wrapper.addEventListener("change", (event) => {
if (event.target.matches('[data-datepicker-target="value"]'))
console.log(event.target.value); // "2026-11-23"
});

The event fires once per committed value β€” on each pick for date and date-time fields, and when the calendar closes for date range filters β€” and does not re-fire when the same value is picked again. This is the mechanism Catalyst's own date filters use: their hidden input carries the change listener that submits the filter.

Recipes​

Date pickers limit year navigation to Β±50 years around the current year. To let users pick from a wider range (1900–2199), set data-default-year-selector on the input, and add data-min-date / data-max-date (ISO YYYY-MM-DD) if the field needs a custom range:

form_field :birth_date, input_type: :date,
html_attrs: { data: { default_year_selector: true, max_date: Date.current.iso8601 } }