You can define a rule to compare two dates.
First you need to convert them to an integer in order to be able to use the integrated validator. The best way to do this is to specify a date for the unix timestamp before validation and in the format you need after validation.
Add them to your model:
public function beforeValidate() {
$this->td_to = strtotime($this->td_to);
$this->td_from = strtotime($this->td_from);
return parent::beforeValidate();
}
public function afterValidate() {
$this->td_to = date(FORMAT, $this->td_to);
$this->td_from = date(FORMAT, $this->td_from);
}
Add a new rule inside your method rules
return [
['td_to', 'compare', 'operator' => '<', 'type' => 'number', 'compareAttribute' => 'td_from', 'whenClient' => 'js:function () { /* validate values with jQuery or js here and if valid return true */ return true; }'],
];
ajax. , js, whenClient .