Don't work custom validation


I’m used custom validation but don’t work.

I need to validate two dates. The start date must be less than the end date. I think with a custom validation can do it, but I have not made ​​it work.

Even this small example not work.

    public function rules()


        return [

            [['fechafactura', 'fechainicio',  'orden_numero'], 'required'],

            [['fechafactura', 'fechainicio', 'fechafin'], 'safe'],

            [['orden_numero'], 'integer'],

            ['fechafin', 'required_date'],



    public function required_date($attribute, $params){


            $this->addError($attribute, 'Date can not be empty');



anyone know where I 'm wrong. I hope you can help me.

Try removing "safe" validator.

Softark Thanks for your reply, but I try and do not work . I can not be doing wrong

See if that works:

['fechafin', 'required_date', 'skipOnEmpty' => false],

If that doesn´t work. Check your scenario.

Study, hope to be able to use in the future.