Date Validations For Datepicker


I am using a datepicker widget in my form.

How do I validate the date field such that it wont accept any date earlier than today.

You must add your own date validator, read this.

We can use custom function in model for validation.

public function rules()


           return array(

                  array('start_date', 'checkDate','on'=>'create'),



public function checkDate() 



            $newtime=strtotime(date('Y-m-d H:i',strtotime('-1 minute')));

            if($strtime<$newtime) {

            	$this->addError('start_date','Please select a valid date');



You can use widget options or add custom rule.





    'flat'=>true,//remove to hide the datepicker


        'dateFormat' => 'yy-mm-dd',





        'minDate' => '2000-01-01',      // Set the current date here.

        'maxDate' => '2099-12-31',      // maximum date







I have my datepicker which has Y-m-d format.

I have used beforeSave() method to convert it into d-m-Y format.

How do I validate my date field before save?