can any post the how to filter a grid view timestamp(Y-m-d h:m:s) column using date picker. my model is below
public function search()
{
$criteria=new CDbCriteria();
$criteria->condition="time_up BETWEEN UNIX_TIMESTAMP('$this->time_up_from') AND UNIX_TIMESTAMP('$this->time_up_to')";
$criteria->compare('proc_id',$this->proc_id);
$criteria->compare('book_id',$this->book_id);
$criteria->compare('Project_name', $this->Project_name);
$criteria->compare('isbn_no', $this->isbn_no);
$criteria->compare('book_title',$this->book_title);
$criteria->compare('totalpage',$this->totalpage,true);
$criteria->compare('totaltime',$this->totaltime,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>100
),
));
}
for the normal particular condition its working by below condition
$criteria->condition = " time_up LIKE '$this->time_up%'";
for date range its not working i tried also wiki/142/ in yii website but no use. kindly help in this.or give some other methods to darange search for timestamp.
My inputs from advanced search form
<div class=" wide form">
<?php $form=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'get',
)); ?>
<div class="row">
<?php echo "Time UP from"; ?>
<?php $this->widget('zii.widgets.jui.CJuiDatePicker',
array(
'model'=>$model,
'name'=>'Process[time_up_from]',
// Model attribute filed which hold user input
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd',),
'htmlOptions'=>array(
'style'=>'height:20px;width:100px',
'size'=>15,
//'value'=>date('Y-m-d'),
/*'onchange'=>"$.fn.yiiGridView.update('books-grid', {data: $(this).serialize()});" */),));?>
</div>
<?php echo "Time Up to"; ?>
<?php $this->widget('zii.widgets.jui.CJuiDatePicker',
array(
'model'=>$model,
'name'=>'Process[time_up_to]',
// Model attribute filed which hold user input
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd',),
'htmlOptions'=>array(
'style'=>'height:20px;width:100px',
'size'=>15,
//'value'=>date('Y-m-d'),
/*'onchange'=>"$.fn.yiiGridView.update('books-grid', {data: $(this).serialize()});"*/ ),));?>
</div>
<?php echo CHtml::submitButton('Search'); ?>
ANSWER FOR THE PROBLEM
hi i found the answer its just a if condition before criteria condition
`if(strlen($this->time_up_from) && strlen($this->time_up_to))
{
$criteria->condition="time_up BETWEEN UNIX_TIMESTAMP('$this->time_up_from') AND UNIX_TIMESTAMP('$this->time_up_to')";
}
now its working fine. @bool.dev thank you very much for your suggestions.thanks alot.