i know it only supports types number and string but if you use a before validate something like
$this->end_date = strtotime($this->end_date);
$this->start_date = strtotime($this->start_date);
it will always not validate saying it is greater than start date is greater than end date.
I tried doing a custom validator exact copy and paste from the docs but i couldn’t get it to fire either. I even had it only returning an error and it still wouldn’t show it.
you can write custom validator to compare dates here you go
public function rules()
{
return [
//...
['end_date', 'compareDates'],
//...
];
}
public function compareDates()
{
$end_date = strtotime($this->end_date);
$start_date = strtotime($this->start_date);
if (!$this->hasErrors() && $end_date > $start_date) {
$this->addError('end_date', 'End date is not valid.');
}
}
It’s more likely to be that if end date is before start date then it’s worth flagging as invalid. Code above should probably be: if (!$this->hasErrors() && $end_date < $start_date) {