I
I
Ilya Karavaev2018-06-18 10:51:15
Yii
Ilya Karavaev, 2018-06-18 10:51:15

What is wrong with date validation in Yii2?

Please help with date validation. I didn’t notice such a problem before, but now we get a valid answer for a non-valid date (although of course there is a controversial point with the invalid date).
Essence:

public function rules() {
    return [ ['published_at', 'date', 'format' => 'php:d.m.Y']];
}

When you enter the date in the form field: 01/01/201, the validation passes with a bang and skips the date.
Although after, through Yii::$app->formatter->asTimestamp($model->published_at) we get an exception that the date is not valid.
Who faced and how validated?
UPD:
Arik , DateTime::createFromFormat('dmY', '01/01/201') - you tell where is the year, where is the month, where is the day.
And here DateTime( '01 /01/201
' ) ask php to guess, and it tries to guess like this: => '01/01/1970' can you think of it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arman, 2018-06-18
@Quieteroks

Maybe:
1. 01/01/201 - a valid date for 201 2. timestamp for such a year
simply does not exist, at least 1970

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question