# DateValidator

> DateValidator verifies if the attribute represents a date, time or datetime in a proper $format.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [validators](/docs/api/yii/validators/index.md) › DateValidator

| class | `yii\validators\DateValidator` |
| --- | --- |
| Extends | [`Validator`](/docs/api/yii/validators/validator/index.md) » [`yii\base\Component`](/docs/api/yii/base/component/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/validators/DateValidator.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/validators/DateValidator.php#L38) |

DateValidator verifies if the attribute represents a date, time or datetime in a proper [`$format`](/docs/api/yii/validators/datevalidator/index.md#property-format).

It can also parse internationalized dates in a specific [`$locale`](/docs/api/yii/validators/datevalidator/index.md#property-locale) like e.g. `12 мая 2014` when [`$format`](/docs/api/yii/validators/datevalidator/index.md#property-format)
is configured to use a time pattern in ICU format.

It is further possible to limit the date within a certain range using [`$min`](/docs/api/yii/validators/datevalidator/index.md#property-min) and [`$max`](/docs/api/yii/validators/datevalidator/index.md#property-max).

Additional to validating the date it can also export the parsed timestamp as a machine readable format
which can be configured using [`$timestampAttribute`](/docs/api/yii/validators/datevalidator/index.md#property-timestampAttribute). For values that include time information (not date-only values)
also the time zone will be adjusted. The time zone of the input value is assumed to be the one specified by the [`$timeZone`](/docs/api/yii/validators/datevalidator/index.md#property-timeZone)
property and the target timeZone will be UTC when [`$timestampAttributeFormat`](/docs/api/yii/validators/datevalidator/index.md#property-timestampAttributeFormat) is `null` (exporting as UNIX timestamp)
or [`$timestampAttributeTimeZone`](/docs/api/yii/validators/datevalidator/index.md#property-timestampAttributeTimeZone) otherwise. If you want to avoid the time zone conversion, make sure that [`$timeZone`](/docs/api/yii/validators/datevalidator/index.md#property-timeZone) and
[`$timestampAttributeTimeZone`](/docs/api/yii/validators/datevalidator/index.md#property-timestampAttributeTimeZone) are the same.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-attributeNames"></span>[`$attributeNames`](/docs/api/yii/validators/validator/index.md#property-attributeNames) read-only | `array` | Attribute names. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| <span id="property-attributes"></span>[`$attributes`](/docs/api/yii/validators/validator/index.md#property-attributes) | `array\|string` | Attributes to be validated by this validator. Default: `[]`. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| <span id="property-behaviors"></span>[`$behaviors`](/docs/api/yii/base/component/index.md#property-behaviors) read-only | `array<`[`yii\base\Behavior`](/docs/api/yii/base/behavior/index.md)`<static>>` | List of behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="property-builtInValidators"></span>[`$builtInValidators`](/docs/api/yii/validators/validator/index.md#property-builtInValidators) static | `array` | List of built-in validators (name => class or configuration) Default: `['boolean' => 'yii\validators\BooleanValidator', 'captcha' => 'yii\captcha\CaptchaValidator', 'compare' => 'yii\validators\CompareValidator', 'date' => 'yii\validators\DateValidator', 'datetime' => ['class' => 'yii\validators\DateValidator', 'type' => \yii\validators\DateValidator::TYPE_DATETIME], 'time' => ['class' => 'yii\validators\DateValidator', 'type' => \yii\validators\DateValidator::TYPE_TIME], 'default' => 'yii\validators\DefaultValueValidator', 'double' => 'yii\validators\NumberValidator', 'each' => 'yii\validators\EachValidator', 'email' => 'yii\validators\EmailValidator', 'exist' => 'yii\validators\ExistValidator', 'file' => 'yii\validators\FileValidator', 'filter' => 'yii\validators\FilterValidator', 'image' => 'yii\validators\ImageValidator', 'in' => 'yii\validators\RangeValidator', 'integer' => ['class' => 'yii\validators\NumberValidator', 'integerOnly' => true], 'match' => 'yii\validators\RegularExpressionValidator', 'number' => 'yii\validators\NumberValidator', 'required' => 'yii\validators\RequiredValidator', 'safe' => 'yii\validators\SafeValidator', 'string' => 'yii\validators\StringValidator', 'trim' => ['class' => 'yii\validators\TrimValidator', 'skipOnArray' => true], 'unique' => 'yii\validators\UniqueValidator', 'url' => 'yii\validators\UrlValidator', 'ip' => 'yii\validators\IpValidator']`. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| [`$defaultTimeZone`](#property-defaultTimeZone) | `string` | The default timezone used for parsing when no time parts are provided in the format. Default: `'UTC'`. Available since 2.0.39. | `DateValidator` |
| <span id="property-enableClientValidation"></span>[`$enableClientValidation`](/docs/api/yii/validators/validator/index.md#property-enableClientValidation) | `bool` | Whether to enable client-side validation for this validator. Default: `true`. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| <span id="property-except"></span>[`$except`](/docs/api/yii/validators/validator/index.md#property-except) | `array\|string` | Scenarios that the validator should not be applied to. Default: `[]`. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| [`$format`](#property-format) | `string\|null` | The date format that the value being validated should follow. Default: `null`. | `DateValidator` |
| <span id="property-isEmpty"></span>[`$isEmpty`](/docs/api/yii/validators/validator/index.md#property-isEmpty) | `callable\|null` | A PHP callable that replaces the default implementation of [`isEmpty()`](/docs/api/yii/validators/validator/index.md#method-isEmpty). Default: `null`. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| [`$locale`](#property-locale) | `string\|null` | The locale ID that is used to localize the date parsing. Default: `null`. | `DateValidator` |
| [`$max`](#property-max) | `int\|string\|null` | Upper limit of the date. Default: `null`. Available since 2.0.4. | `DateValidator` |
| [`$maxString`](#property-maxString) | `string\|null` | User friendly value of upper limit to display in the error message. Default: `null`. Available since 2.0.4. | `DateValidator` |
| <span id="property-message"></span>[`$message`](/docs/api/yii/validators/validator/index.md#property-message) | `string\|null` | The user-defined error message. Default: `null`. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| [`$min`](#property-min) | `int\|string\|null` | Lower limit of the date. Default: `null`. Available since 2.0.4. | `DateValidator` |
| [`$minString`](#property-minString) | `string\|null` | User friendly value of lower limit to display in the error message. Default: `null`. Available since 2.0.4. | `DateValidator` |
| <span id="property-on"></span>[`$on`](/docs/api/yii/validators/validator/index.md#property-on) | `array\|string` | Scenarios that the validator can be applied to. Default: `[]`. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| <span id="property-skipOnEmpty"></span>[`$skipOnEmpty`](/docs/api/yii/validators/validator/index.md#property-skipOnEmpty) | `bool` | Whether this validation rule should be skipped if the attribute value is null or an empty string. Default: `true`. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| <span id="property-skipOnError"></span>[`$skipOnError`](/docs/api/yii/validators/validator/index.md#property-skipOnError) | `bool` | Whether this validation rule should be skipped if the attribute being validated already has some validation error according to some previous rules. Default: `true`. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| <span id="property-strictDateFormat"></span>`$strictDateFormat` | `bool` | Set this parameter to true if you need strict date format validation (e.g. only such dates pass validation for the following format 'yyyy-MM-dd': '0011-03-25', '2019-04-30' etc. and not '18-05-15', '2017-Mar-14' etc. which pass validation if this parameter is set to false) Default: `false`. Available since 2.0.22. | `DateValidator` |
| [`$timestampAttribute`](#property-timestampAttribute) | `string\|null` | The name of the attribute to receive the parsing result. Default: `null`. | `DateValidator` |
| [`$timestampAttributeFormat`](#property-timestampAttributeFormat) | `string\|null` | The format to use when populating the [`$timestampAttribute`](/docs/api/yii/validators/datevalidator/index.md#property-timestampAttribute). Default: `null`. Available since 2.0.4. | `DateValidator` |
| [`$timestampAttributeTimeZone`](#property-timestampAttributeTimeZone) | `string` | The timezone to use when populating the [`$timestampAttribute`](/docs/api/yii/validators/datevalidator/index.md#property-timestampAttribute) with [`$timestampAttributeFormat`](/docs/api/yii/validators/datevalidator/index.md#property-timestampAttributeFormat). Default: `'UTC'`. Available since 2.0.4. | `DateValidator` |
| [`$timeZone`](#property-timeZone) | `string\|null` | The timezone to use for parsing date and time values. Default: `null`. | `DateValidator` |
| <span id="property-tooBig"></span>`$tooBig` | `string` | User-defined error message used when the value is bigger than [`$max`](/docs/api/yii/validators/datevalidator/index.md#property-max). Default: `null`. Available since 2.0.4. | `DateValidator` |
| <span id="property-tooSmall"></span>`$tooSmall` | `string` | User-defined error message used when the value is smaller than [`$min`](/docs/api/yii/validators/datevalidator/index.md#property-min). Default: `null`. Available since 2.0.4. | `DateValidator` |
| [`$type`](#property-type) | `string` | The type of the validator. Default: `self::TYPE_DATE`. Available since 2.0.8. | `DateValidator` |
| <span id="property-validationAttributes"></span>[`$validationAttributes`](/docs/api/yii/validators/validator/index.md#property-validationAttributes) read-only | `array\|null` | List of attribute names. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| <span id="property-when"></span>[`$when`](/docs/api/yii/validators/validator/index.md#property-when) | `callable\|null` | A PHP callable whose return value determines whether this validator should be applied. Default: `null`. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| <span id="property-whenClient"></span>[`$whenClient`](/docs/api/yii/validators/validator/index.md#property-whenClient) | `string\|null` | A JavaScript function name whose return value determines whether this validator should be applied on the client-side. Default: `null`. | [`Validator`](/docs/api/yii/validators/validator/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/component/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__clone"></span>[`__clone()`](/docs/api/yii/base/component/index.md#method-__clone) | This method is called after the object is created by cloning an existing one. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/component/index.md#method-__get) | Returns the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/component/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/component/index.md#method-__set) | Sets the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/component/index.md#method-__unset) | Sets a component property to be null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-addError"></span>[`addError()`](/docs/api/yii/validators/validator/index.md#method-addError) | Adds an error about the specified attribute to the model object. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| <span id="method-attachBehavior"></span>[`attachBehavior()`](/docs/api/yii/base/component/index.md#method-attachBehavior) | Attaches a behavior to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehaviors"></span>[`attachBehaviors()`](/docs/api/yii/base/component/index.md#method-attachBehaviors) | Attaches a list of behaviors to the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-behaviors"></span>[`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) | Returns a list of behaviors that this component should behave as. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/component/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/component/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-clientValidateAttribute"></span>[`clientValidateAttribute()`](/docs/api/yii/validators/validator/index.md#method-clientValidateAttribute) | Returns the JavaScript needed for performing client-side validation. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| <span id="method-createValidator"></span>[`createValidator()`](/docs/api/yii/validators/validator/index.md#method-createValidator) static | Creates a validator object. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| <span id="method-detachBehavior"></span>[`detachBehavior()`](/docs/api/yii/base/component/index.md#method-detachBehavior) | Detaches a behavior from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-detachBehaviors"></span>[`detachBehaviors()`](/docs/api/yii/base/component/index.md#method-detachBehaviors) | Detaches all behaviors from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-ensureBehaviors"></span>[`ensureBehaviors()`](/docs/api/yii/base/component/index.md#method-ensureBehaviors) | Makes sure that the behaviors declared in [`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) are attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getAttributeNames"></span>[`getAttributeNames()`](/docs/api/yii/validators/validator/index.md#method-getAttributeNames) | Returns cleaned attribute names without the `!` character at the beginning. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| <span id="method-getBehavior"></span>[`getBehavior()`](/docs/api/yii/base/component/index.md#method-getBehavior) | Returns the named behavior object. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehaviors"></span>[`getBehaviors()`](/docs/api/yii/base/component/index.md#method-getBehaviors) | Returns all behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getClientOptions"></span>[`getClientOptions()`](/docs/api/yii/validators/validator/index.md#method-getClientOptions) | Returns the client-side validation options. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| <span id="method-getFormattedClientMessage"></span>[`getFormattedClientMessage()`](/docs/api/yii/validators/validator/index.md#method-getFormattedClientMessage) | Returns the formatted validation message for client-side validation. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| <span id="method-getValidationAttributes"></span>[`getValidationAttributes()`](/docs/api/yii/validators/validator/index.md#method-getValidationAttributes) | Returns a list of attributes this validator applies to. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| <span id="method-hasEventHandlers"></span>[`hasEventHandlers()`](/docs/api/yii/base/component/index.md#method-hasEventHandlers) | Returns a value indicating whether there is any handler attached to the named event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/component/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/component/index.md#method-hasProperty) | Returns a value indicating whether a property is defined for this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`init()`](#method-init) | Initializes the object. | `DateValidator` |
| <span id="method-isActive"></span>[`isActive()`](/docs/api/yii/validators/validator/index.md#method-isActive) | Returns a value indicating whether the validator is active for the given scenario and attribute. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| <span id="method-isEmpty"></span>[`isEmpty()`](/docs/api/yii/validators/validator/index.md#method-isEmpty) | Checks if the given value is empty. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| <span id="method-off"></span>[`off()`](/docs/api/yii/base/component/index.md#method-off) | Detaches an existing event handler from this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-on"></span>[`on()`](/docs/api/yii/base/component/index.md#method-on) | Attaches an event handler to an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-trigger"></span>[`trigger()`](/docs/api/yii/base/component/index.md#method-trigger) | Triggers an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-validate"></span>[`validate()`](/docs/api/yii/validators/validator/index.md#method-validate) | Validates a given value. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| [`validateAttribute()`](#method-validateAttribute) | Validates a single attribute. | `DateValidator` |
| <span id="method-validateAttributes"></span>[`validateAttributes()`](/docs/api/yii/validators/validator/index.md#method-validateAttributes) | Validates the specified object. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| <span id="method-formatMessage"></span>[`formatMessage()`](/docs/api/yii/validators/validator/index.md#method-formatMessage) protected | Formats a mesage using the I18N, or simple strtr if `\Yii::$app` is not available. | [`Validator`](/docs/api/yii/validators/validator/index.md) |
| [`parseDateValue()`](#method-parseDateValue) protected | Parses date string into UNIX timestamp. | `DateValidator` |
| [`validateValue()`](#method-validateValue) protected | Validates a value. | `DateValidator` |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-TYPE_DATE"></span>`TYPE_DATE` | `'date'` | Constant for specifying the validation [`$type`](/docs/api/yii/validators/datevalidator/index.md#property-type) as a date value, used for validation with intl short format. Available since 2.0.8. | `DateValidator` |
| <span id="const-TYPE_DATETIME"></span>`TYPE_DATETIME` | `'datetime'` | Constant for specifying the validation [`$type`](/docs/api/yii/validators/datevalidator/index.md#property-type) as a datetime value, used for validation with intl short format. Available since 2.0.8. | `DateValidator` |
| <span id="const-TYPE_TIME"></span>`TYPE_TIME` | `'time'` | Constant for specifying the validation [`$type`](/docs/api/yii/validators/datevalidator/index.md#property-type) as a time value, used for validation with intl short format. Available since 2.0.8. | `DateValidator` |

## Property details

### $defaultTimeZone <span id="property-defaultTimeZone"></span>

```php
public string $defaultTimeZone = 'UTC'
```

The default timezone used for parsing when no time parts are provided in the format.

See [`$timestampAttributeTimeZone`](/docs/api/yii/validators/datevalidator/index.md#property-timestampAttributeTimeZone) for more description.

**Since**

2.0.39

### $format <span id="property-format"></span>

```php
public string|null $format = null
```

The date format that the value being validated should follow.

This can be a date time pattern as described in the [ICU manual](https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax).

Alternatively this can be a string prefixed with `php:` representing a format that can be recognized by the PHP Datetime class.
Please refer to <https://www.php.net/manual/en/datetime.createfromformat.php> on supported formats.

If this property is not set, the default value will be obtained from `Yii::$app->formatter->dateFormat`, see [`Formatter::$dateFormat`](/docs/api/yii/i18n/formatter/index.md#property-dateFormat) for details.
Since version 2.0.8 the default value will be determined from different formats of the formatter class,
dependent on the value of [`$type`](/docs/api/yii/validators/datevalidator/index.md#property-type):

- if type is [`TYPE_DATE`](/docs/api/yii/validators/datevalidator/index.md#const-TYPE_DATE), the default value will be taken from [`Formatter::$dateFormat`](/docs/api/yii/i18n/formatter/index.md#property-dateFormat),
- if type is [`TYPE_DATETIME`](/docs/api/yii/validators/datevalidator/index.md#const-TYPE_DATETIME), it will be taken from [`Formatter::$datetimeFormat`](/docs/api/yii/i18n/formatter/index.md#property-datetimeFormat),
- and if type is [`TYPE_TIME`](/docs/api/yii/validators/datevalidator/index.md#const-TYPE_TIME), it will be [`Formatter::$timeFormat`](/docs/api/yii/i18n/formatter/index.md#property-timeFormat).

Here are some example values:

```
'MM/dd/yyyy' // date in ICU format
'php:m/d/Y' // the same date in PHP format
'MM/dd/yyyy HH:mm' // not only dates but also times can be validated
```

**Note:** the underlying date parsers being used vary dependent on the format. If you use the ICU format and
the [PHP intl extension](https://www.php.net/manual/en/book.intl.php) is installed, the [IntlDateFormatter](https://www.php.net/manual/en/intldateformatter.parse.php)
is used to parse the input value. In all other cases the PHP [DateTime](https://www.php.net/manual/en/datetime.createfromformat.php) class
is used. The IntlDateFormatter has the advantage that it can parse international dates like `12. Mai 2015` or `12 мая 2014`, while the
PHP parser is limited to English only. The PHP parser however is more strict about the input format as it will not accept
`12.05.05` for the format `php:d.m.Y`, but the IntlDateFormatter will accept it for the format `dd.MM.yyyy`.
If you need to use the IntlDateFormatter you can avoid this problem by specifying a [minimum date](/docs/api/yii/validators/datevalidator/index.md#property-min).

### $locale <span id="property-locale"></span>

```php
public string|null $locale = null
```

The locale ID that is used to localize the date parsing.

This is only effective when the [PHP intl extension](https://www.php.net/manual/en/book.intl.php) is installed.
If not set, the locale of the [formatter](/docs/api/yii/base/application/index.md#property-formatter) will be used.
See also [`Formatter::$locale`](/docs/api/yii/i18n/formatter/index.md#property-locale).

### $max <span id="property-max"></span>

```php
public int|string|null $max = null
```

Upper limit of the date.

Defaults to null, meaning no upper limit.
This can be a unix timestamp or a string representing a date time value.
If this property is a string, [`$format`](/docs/api/yii/validators/datevalidator/index.md#property-format) will be used to parse it.

**Since**

2.0.4

### $maxString <span id="property-maxString"></span>

```php
public string|null $maxString = null
```

User friendly value of upper limit to display in the error message.

If this property is null, the value of [`$max`](/docs/api/yii/validators/datevalidator/index.md#property-max) will be used (before parsing).

**Since**

2.0.4

### $min <span id="property-min"></span>

```php
public int|string|null $min = null
```

Lower limit of the date.

Defaults to null, meaning no lower limit.
This can be a unix timestamp or a string representing a date time value.
If this property is a string, [`$format`](/docs/api/yii/validators/datevalidator/index.md#property-format) will be used to parse it.

**Since**

2.0.4

### $minString <span id="property-minString"></span>

```php
public string|null $minString = null
```

User friendly value of lower limit to display in the error message.

If this property is null, the value of [`$min`](/docs/api/yii/validators/datevalidator/index.md#property-min) will be used (before parsing).

**Since**

2.0.4

### $timestampAttribute <span id="property-timestampAttribute"></span>

```php
public string|null $timestampAttribute = null
```

The name of the attribute to receive the parsing result.

When this property is not null and the validation is successful, the named attribute will
receive the parsing result.

This can be the same attribute as the one being validated. If this is the case,
the original value will be overwritten with the timestamp value after successful validation.

Note, that when using this property, the input value will be converted to a unix timestamp, which by definition
is in [default UTC time zone](/docs/api/yii/validators/datevalidator/index.md#property-defaultTimeZone), so a conversion from the [input time zone](/docs/api/yii/validators/datevalidator/index.md#property-timeZone) to
the default one will be performed. If you want to change the default time zone, set the [`$defaultTimeZone`](/docs/api/yii/validators/datevalidator/index.md#property-defaultTimeZone) property.
When defining [`$timestampAttributeFormat`](/docs/api/yii/validators/datevalidator/index.md#property-timestampAttributeFormat) you can further control the conversion by setting
[`$timestampAttributeTimeZone`](/docs/api/yii/validators/datevalidator/index.md#property-timestampAttributeTimeZone) to a different value than `'UTC'`.

### $timestampAttributeFormat <span id="property-timestampAttributeFormat"></span>

```php
public string|null $timestampAttributeFormat = null
```

The format to use when populating the [`$timestampAttribute`](/docs/api/yii/validators/datevalidator/index.md#property-timestampAttribute).

The format can be specified in the same way as for [`$format`](/docs/api/yii/validators/datevalidator/index.md#property-format).

If not set, [`$timestampAttribute`](/docs/api/yii/validators/datevalidator/index.md#property-timestampAttribute) will receive a UNIX timestamp.
If [`$timestampAttribute`](/docs/api/yii/validators/datevalidator/index.md#property-timestampAttribute) is not set, this property will be ignored.

**Since**

2.0.4

### $timestampAttributeTimeZone <span id="property-timestampAttributeTimeZone"></span>

```php
public string $timestampAttributeTimeZone = 'UTC'
```

The timezone to use when populating the [`$timestampAttribute`](/docs/api/yii/validators/datevalidator/index.md#property-timestampAttribute) with [`$timestampAttributeFormat`](/docs/api/yii/validators/datevalidator/index.md#property-timestampAttributeFormat).

Defaults to `UTC`.

This can be any value that may be passed to [date_default_timezone_set()](https://www.php.net/manual/en/function.date-default-timezone-set.php)
e.g. `UTC`, `Europe/Berlin` or `America/Chicago`.
Refer to the [php manual](https://www.php.net/manual/en/timezones.php) for available timezones.

If [`$timestampAttributeFormat`](/docs/api/yii/validators/datevalidator/index.md#property-timestampAttributeFormat) is not set, this property will be ignored.

**Since**

2.0.4

### $timeZone <span id="property-timeZone"></span>

```php
public string|null $timeZone = null
```

The timezone to use for parsing date and time values.

This can be any value that may be passed to [date_default_timezone_set()](https://www.php.net/manual/en/function.date-default-timezone-set.php)
e.g. `UTC`, `Europe/Berlin` or `America/Chicago`.
Refer to the [php manual](https://www.php.net/manual/en/timezones.php) for available timezones.
If this property is not set, [`Application::$timeZone`](/docs/api/yii/base/application/index.md#property-timeZone) will be used.

### $type <span id="property-type"></span>

```php
public string $type = self::TYPE_DATE
```

The type of the validator.

Indicates, whether a date, time or datetime value should be validated.
This property influences the default value of [`$format`](/docs/api/yii/validators/datevalidator/index.md#property-format) and also sets the correct behavior when [`$format`](/docs/api/yii/validators/datevalidator/index.md#property-format) is one of the intl
short formats, `short`, `medium`, `long`, or `full`.

This is only effective when the [PHP intl extension](https://www.php.net/manual/en/book.intl.php) is installed.

This property can be set to the following values:

- [`TYPE_DATE`](/docs/api/yii/validators/datevalidator/index.md#const-TYPE_DATE) - (default) for validating date values only, that means only values that do not include a time range are valid.
- [`TYPE_DATETIME`](/docs/api/yii/validators/datevalidator/index.md#const-TYPE_DATETIME) - for validating datetime values, that contain a date part as well as a time part.
- [`TYPE_TIME`](/docs/api/yii/validators/datevalidator/index.md#const-TYPE_TIME) - for validating time values, that contain no date information.

**Since**

2.0.8

## Method details

### init() <span id="method-init"></span>

```php
public function init(): mixed
```

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the
given configuration.

**Returns**

`mixed`

### validateAttribute() <span id="method-validateAttribute"></span>

```php
public function validateAttribute(mixed $model, mixed $attribute): mixed
```

Validates a single attribute.

Child classes must implement this method to provide the actual validation logic.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | `mixed` | The data model to be validated |
| `$attribute` | `mixed` | The name of the attribute to be validated. |

**Returns**

`mixed`

### parseDateValue() <span id="method-parseDateValue"></span>

```php
protected function parseDateValue(mixed $value): int|false
```

Parses date string into UNIX timestamp.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | String representing date |

**Returns**

`int|false`: A UNIX timestamp or `false` on failure.

### validateValue() <span id="method-validateValue"></span>

```php
protected function validateValue(mixed $value): array|null
```

Validates a value.

A validator class can implement this method to support data validation out of the context of a data model.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | The data value to be validated. |

**Returns**

`array|null`: The error message and the array of parameters to be inserted into the error message. if (!$valid) { return [$this->message, [ 'param1' => $this->param1, 'formattedLimit' => Yii::$app->formatter->asShortSize($this->getSizeLimit()), 'mimeTypes' => implode(', ', $this->mimeTypes), 'param4' => 'etc...', ]]; } return null; for this example `message` template can contain `{param1}`, `{formattedLimit}`, `{mimeTypes}`, `{param4}` Null should be returned if the data is valid.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): if the validator does not supporting data validation without a model