2017-05-01 08:54:18 +02:00
|
|
|
# DateTime
|
|
|
|
|
|
|
|
- `DateTime()`
|
|
|
|
- `DateTime(string $format)`
|
|
|
|
|
2018-01-30 18:57:07 +01:00
|
|
|
Validates whether an input is a date/time or not. The `$format` argument should
|
|
|
|
be in accordance to PHP's [date()](http://php.net/date) function.
|
2017-05-01 08:54:18 +02:00
|
|
|
|
|
|
|
```php
|
|
|
|
v::dateTime()->validate('2009-01-01'); // true
|
|
|
|
```
|
|
|
|
|
|
|
|
Also accepts strtotime values:
|
|
|
|
|
|
|
|
```php
|
|
|
|
v::dateTime()->validate('now'); // true
|
|
|
|
```
|
|
|
|
|
|
|
|
And `DateTimeInterface` instances:
|
|
|
|
|
|
|
|
```php
|
|
|
|
v::dateTime()->validate(new DateTime()); // true
|
|
|
|
v::dateTime()->validate(new DateTimeImmutable()); // true
|
|
|
|
```
|
|
|
|
|
|
|
|
You can pass a format when validating strings:
|
|
|
|
|
|
|
|
```php
|
|
|
|
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}}`.
|
|
|
|
|
2019-05-11 18:32:13 +02:00
|
|
|
## Categorization
|
|
|
|
|
|
|
|
- Date and Time
|
|
|
|
|
2017-05-01 08:54:18 +02:00
|
|
|
## Changelog
|
|
|
|
|
|
|
|
Version | Description
|
|
|
|
--------|-------------
|
2019-05-11 21:44:44 +02:00
|
|
|
2.0.0 | Created
|
2017-05-01 08:54:18 +02:00
|
|
|
|
|
|
|
***
|
|
|
|
See also:
|
|
|
|
|
|
|
|
- [Between](Between.md)
|
2018-12-11 13:31:50 +01:00
|
|
|
- [Date](Date.md)
|
2017-05-01 08:54:18 +02:00
|
|
|
- [LeapDate](LeapDate.md)
|
|
|
|
- [LeapYear](LeapYear.md)
|
2018-12-11 13:31:50 +01:00
|
|
|
- [MinAge](MinAge.md)
|
2018-01-30 18:57:07 +01:00
|
|
|
- [Time](Time.md)
|