Unable To Search Date In Cgridview

Hi Everyone,

All i want to do is just able to filter using date on gridview / advanced search section. i have search for the answer and tried several method but unfortunately, the problem is still persist to me. i’m even not using between range of date scenario. the objective is simple so the user should be able to search on spesific date, and all data on that date should be displayed on the gridview.

here is the date widget on my search form :

<div class="row">

		<?php echo $form->label($model,'tgl_surat_jalan'); ?>


		 <?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(



		'value' => $model->tgl_surat_jalan, 		

        // additional javascript options for the date picker plugin









        )); ?>


and here is the search criteria on my model (as i point my dataProvider to $model->dibuat()) :

public function dibuat()


		// Warning: Please modify the following code to remove attributes that

		// should not be searched.

		$criteria=new CDbCriteria;














		$criteria->compare('tgl_surat_jalan',CDateTimeParser::parse($this->tgl_surat_jalan, 'yyyy-MM-DD'),true);



		return new CActiveDataProvider($this, array(




i’m able filter with the other attribute, but if i tried to filter using datefield then the search function is not working. am i missing something here? i’m just curious how search method work for datefield in yii.



Try to adjust the pattern for CDateTimeParser.parse(). It’s still at the default in your case which absolutely doesn’t match the format you specified for the date picker.

thanks for the reply, i’ve tried to change the datefortmat on my model :

CDateTimeParser::parse($this->tgl_surat_jalan, 'yy-mm-dd')

to match the dateformat on the datepicker as you suggest but no success. i’m still unable to filter datefield.

am i missing something? the date format should be year-month-date as its the same with the date format on database.

Oh, so the field in the database is of the VARCHAR type? CDateTimeParser.parse() will produce an integer representing a unix timestamp. I think you do not need to use it at all. Just set a validation rule in place for the search scenario.

actually, the field in the database is DATE type with (Y-m-d) format i.e: 2013-01-20.

i see, so CDateTimeParser.parse() will produce integer unix stamp format. so is there any other way to format the datefield after the user clicked search button? in case the dateformat returned by the datepicker is incorrect.

and i also already added the tgl_surat_jalan in rule() on search. but still no success.

and sorry for another silly question, i also have tried to var_dump the $criteria on models, to find out what value $this->tgl_surat_jalan has. but var_dump($criteria) seems it always returning default value with all the fields null. even though i search using multiple conditions. like id and tgl_surat_jalan.

so, where should i put the var_dump to find out what value exactly $this->tgl_surat_jalan has?