S
S
skajtersen2017-06-22 15:00:13
Yii
skajtersen, 2017-06-22 15:00:13

How to make a validation for the entered date so that it is no later than the current day?

The model has an attribute "birthday". How can I use the built-in validator to check that when editing a profile it is impossible to set the date of birth later than the current day?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-06-22
@skajtersen

['birthday', 'date', 'max' => time(), 'tooBig' => 'Дата рождения должна быть не меньше текущей даты'],

www.yiiframework.com/doc-2.0/yii-validators-dateva...

D
Dmitry, 2017-06-22
@slo_nik

Good afternoon.
Try doing this:

['birthday', 'date', 'when' => function($model){
                 return strtotime($model->birthday) < time());
            }, 'message' => 'Дата рождения должна быть не меньше текущей даты'],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question