Compare two dates in rules

I want to compare 2 dates in rules.

When I enter the same date in start_date and end_date, I get the error message "End must be greater than or equal to Start"

The start_date and end_date are datetime fields.

I’m looking for a solution.




return [

            ['end_date', 'date', 'format' => 'php:Y-m-d H:i:s', 'skipOnEmpty' => false],

            ['start_date', 'date', 'format' => 'php:Y-m-d H:i:s', 'skipOnEmpty' => false],

            ['end_date', 'compare', 'compareAttribute' => 'start_date', 'operator' => '>'],

        ];



I think you need custom validation, because you have to compare DATE part of datetime field.

Thx Fabrizio,

I have tried custom validation, but can’t get it to work.

I’m looking for a good example.

I’m using Ajax validation on the client side.