respect-validation/docs/DateTime.md
Henrique Moody 0338e18e83
Rename rule "Date" to "DateTime"
Also change rules to use `DateTimeInterface` and `DateTimeImmutable`
when possible.
2017-05-01 13:16:59 +02:00

968 B

DateTime

  • DateTime()
  • DateTime(string $format)

Validates if input is a date. The $format argument should be in accordance to PHP's date() function.

v::dateTime()->validate('2009-01-01'); // true

Also accepts strtotime values:

v::dateTime()->validate('now'); // true

And DateTimeInterface instances:

v::dateTime()->validate(new DateTime()); // true
v::dateTime()->validate(new DateTimeImmutable()); // true

You can pass a format when validating strings:

v::dateTime('Y-m-d')->validate('01-01-2009'); // false

Format has no effect when validating DateTime instances.

Message template for this validator includes {{format}}.

Changelog

Version Description
2.0.0 Renamed from Date to DateTime
0.3.9 Created as Date

See also: