Downloads this Month Latest Stable Version Build Status Scrutinizer Code Quality Coverage Status


composer require achse/nette-date-time-input


Basic usage is to add into your BaseForm or FormElements trait code like this:

 * @param string $name
 * @param string|NULL $label
 * @param IDateTimeImmutableConverter|string $dateConverterOrFormat
 * @return DateTimeImmutableInput
public function addDate($name, $label = NULL, $dateConverterOrFormat = 'j. n. Y')
	return $this[$name] = DateTimeInputFactory::create($label, $dateConverterOrFormat);


  • You can use any addRule(Form::XXX like you are used to do for any other input.
  • Rules Form::VALID and Form::FILLED are reimplemented to behave according to given DateTime format.

How does it work?

It creates simple text input. Handling client side is fully up to you. (For example:

As result it returns DateTime object. Internally it use:

  • IDateTimeImmutableConverter - responsible for conversion from string to DateTime object and vice versa.
  • IDateTimeImmutableFixer - responsible for removing PHP specific behavior like this:

You can provide both of them as service. If not specified, single new object is created for each input.

Default converter: SimpleDateTimeConverter and what "safe symbols" means?

In PHP, method DateTimeImmutable::createFromFormat has this really unexpected behavior:

Therefore SimpleDateTimeConverter prevents you from being affected by this "language feature".

It works line this:

  1. It strips all duplicate whitespaces and trims the string,
  2. DateTimeImmutable::createFromFormat creates DateTimeImmutable object,
  3. object is formatted by original patter back to string,
  4. string is compared, if is same as input string.

(For more you can see: SimpleDateTimeImmutableConverter::parseValue method.)

But, there is a leading zero problem.

  • You insert: 1. 1. 2015 with pattern d. m. Y,
  • algorithm creates object and ties to compare it with original,
  • but by pattern created: 01. 01. 2015 !== (original) 1. 1. 2015.

Because of this, it's strongly recommended to use only no-leading-zero formats in your datepicker.


  • If you wrote better (alternative) IDateTimeImmutableConverter send me pull request or just send me email. I'll be really happy to integrate it into package.
  • If you have ANY suggestion or idea how to make it better I'll be happy for every opened issue.
  • 4.0.0 4.0.0

    • DateTime changed for DateTimeImmutable (break change)
    • Dropped support for all prior version PHP. Minimal version is 7.2 now.
    • Nette Frorms ^2.4
    • Scrict types, PHPStan added
  • 3.3.0 3.3.0

    • PHP 7 support
  • 3.2.0 3.2.0

    • DateTimeInputFactory added.
    • Fixes in naming (no BC breaks).
  • 3.1.0 3.1.0

    • Tools extracted to separate package.
  • 3.0.0 3.0.0

    • BC Break due renaming
  • 2.0.0 2.0.0

    • When new datetime object is created from string by pattern, default values are used instead of "now" (php default behavior).
    • Improved tests.
    • Documentation.

Is this addon outdated? Did you find an issue? Please report it.

Componette Componette