Wednesday, 24 September 2014

Date Compare in YII model search function


View : Search form

label($model,'fromdate'); ?> widget('zii.widgets.jui.CJuiDatePicker',array( 'id'=>'HolidayHolidayrange_fromdate', 'name'=>'HolidayHolidayrange[fromdate]', 'value'=>$model->fromdate==''?'':date('d-m-Y',strtotime($model->fromdate)), 'options'=>array( 'dateFormat' => 'dd-mm-yy', 'showAnim'=>'slide', 'showButtonPanel'=>true, 'changeMonth'=>true, 'changeYear'=>true, 'yearRange'=>'1900:'.date('Y'), ), 'htmlOptions'=>array( 'style'=>'', 'placeHolder'=>'End Date' ), )); ?>
label($model,'todate'); ?> widget('zii.widgets.jui.CJuiDatePicker',array( 'id'=>'HolidayHolidayrange_todate', 'name'=>'HolidayHolidayrange[todate]', 'value'=>$model->todate==''?'':date('d-m-Y',strtotime($model->todate)), 'options'=>array( 'dateFormat' => 'dd-mm-yy', 'showAnim'=>'slide', 'showButtonPanel'=>true, 'changeMonth'=>true, 'changeYear'=>true, 'yearRange'=>'1900:'.date('Y'), ), 'htmlOptions'=>array( 'style'=>'', 'placeHolder'=>'End Date' ), )); ?>
Model's Search function
public function search()
 {
           ....................
        if(!empty($this->fromdate))  
        $criteria->addCondition('fromdate > "'.date("Y-m-d",strtotime($this->fromdate)).'" ');
   
        if(!empty($this->todate))
        $criteria->addCondition('todate < "'.date("Y-m-d",strtotime($this->todate)).'" ');
         .......................
       }

No comments:

Post a Comment