Skip to content

Datetime

Viames Marino edited this page Feb 26, 2026 · 2 revisions

Pair framework: Datetime

Pair\Html\FormControls\Datetime renders date-time inputs (datetime-local or custom datetime).

Methods

  • datetimeFormat(string $format): self
  • min(string|DateTime $minValue): self
  • max(string|DateTime $maxValue): self
  • value(string|int|float|DateTime|null $value): static
  • render(): string

Behavior

  • Default format is Y-m-d\TH:i:s.
  • Rendered input type is:
    • datetime when Post::usingCustomDatetimepicker() is true
    • datetime-local otherwise
  • Constructor may switch format from translation key FORM_DATETIME_FORMAT when custom picker is enabled.
  • With Env::get('UTC_DATE'), DateTime values are converted to current user timezone before formatting.

Examples

$publishedAt = (new \Pair\Html\FormControls\Datetime('publishedAt'))
    ->min('2026-01-01T00:00:00')
    ->max('2026-12-31T23:59:59')
    ->value(new DateTime('now'))
    ->required();

echo $publishedAt->render();

Custom format for custom picker:

$eventAt = (new \Pair\Html\FormControls\Datetime('eventAt'))
    ->datetimeFormat('d/m/Y H:i')
    ->value(new DateTime('2026-05-20 09:30:00'));

See also: Date, Time, FormControl.

Clone this wiki locally