Property |
Type |
Description |
|
$format |
|
the date format that the value being validated should follow.
This can be a date time pattern as described in the ICU manual.
Alternatively this can be a string prefixed with php: representing a format that can be recognized by the PHP Datetime class.
Please refer to on supported formats.
If this property is not set, the default value will be obtained from Yii::$app->formatter->dateFormat, see [[\yii\i18n\Formatter::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]]:
- if type is [[TYPE_DATE]], the default value will be taken from [[\yii\i18n\Formatter::dateFormat]],
- if type is [[TYPE_DATETIME]], it will be taken from [[\yii\i18n\Formatter::datetimeFormat]],
- and if type is [[TYPE_TIME]], it will be [[\yii\i18n\Formatter::timeFormat]].
Here are some example values:
php
'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 is installed, the IntlDateFormatter
is used to parse the input value. In all other cases the PHP DateTime 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 [[min|minimum date]]. |
|
$locale |
|
the locale ID that is used to localize the date parsing.
This is only effective when the PHP intl extension is installed.
If not set, the locale of the [[\yii\base\Application::formatter|formatter]] will be used.
See also [[\yii\i18n\Formatter::locale]]. |
|
$max |
|
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]] will be used to parse it. |
|
$maxString |
|
user friendly value of upper limit to display in the error message.
If this property is null, the value of [[max]] will be used (before parsing). |
|
$min |
|
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]] will be used to parse it. |
|
$minString |
|
user friendly value of lower limit to display in the error message.
If this property is null, the value of [[min]] will be used (before parsing). |
|
$timeZone |
|
the timezone to use for parsing date and time values.
This can be any value that may be passed to date_default_timezone_set()
e.g. UTC, Europe/Berlin or America/Chicago.
Refer to the php manual for available timezones.
If this property is not set, [[\yii\base\Application::timeZone]] will be used. |
|
$timestampAttribute |
|
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 UTC, so a conversion from the [[$timeZone|input time zone]] to UTC
will be performed. When defining [[$timestampAttributeFormat]] you can control the conversion by
setting [[$timestampAttributeTimeZone]] to a different value than 'UTC'. |
|
$timestampAttributeFormat |
|
the format to use when populating the [[timestampAttribute]].
The format can be specified in the same way as for [[format]].
If not set, [[timestampAttribute]] will receive a UNIX timestamp.
If [[timestampAttribute]] is not set, this property will be ignored. |
|
$timestampAttributeTimeZone |
|
the timezone to use when populating the [[timestampAttribute]]. Defaults to UTC.
This can be any value that may be passed to date_default_timezone_set()
e.g. UTC, Europe/Berlin or America/Chicago.
Refer to the php manual for available timezones.
If [[timestampAttributeFormat]] is not set, this property will be ignored. |
|
$tooBig |
|
user-defined error message used when the value is bigger than [[max]]. |
|
$tooSmall |
|
user-defined error message used when the value is smaller than [[min]]. |
|
$type |
|
the type of the validator. Indicates, whether a date, time or datetime value should be validated.
This property influences the default value of [[format]] and also sets the correct behavior when [[format]] is one of the intl
short formats, short, medium, long, or full.
This is only effective when the PHP intl extension is installed.
This property can be set to the following values:
- [[TYPE_DATE]] - (default) for validating date values only, that means only values that do not include a time range are valid.
- [[TYPE_DATETIME]] - for validating datetime values, that contain a date part as well as a time part.
- [[TYPE_TIME]] - for validating time values, that contain no date information. |
|