yii csqldataprovider date range filter

Hi all,

i have a quetion about "how to implement date range filter in csqldataprovider"

scenenario :

i have a function with 2 parameters from_date and to_date, using datepicker i want to search data




public function actionRawatJalan($from_date, $to_date)

	{

$diagram1 = "SELECT * FROM table WHERE date BETWEEN '$from_date' AND '$to_date'";

		$count = Yii::app()->db->createCommand('SELECT COUNT(*) FROM (' . $diagram1 . ') as count_alias')->queryScalar(); //the count

		$dataProvider = new CSqlDataProvider($diagram1, array(

			'keyField' => 'ID', 

			'totalItemCount'=>$count,

		));

		

		$this->layout='column1';

		return $this->render('viewData', array(

			'dataProvider' => $dataProvider,

		));

	}




In viewData.php




<div class="search-form">

							<?php $form=$this->beginWidget('CActiveForm', array(

								'id'=>'page-form',

								'enableAjaxValidation'=>true,

							)); ?>

							 

							<b>Dari :</b>

							<?php

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

								'name'=>'from_date',  // name of post parameter

								 'options'=>array(

									'showAnim'=>'fold',

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

									'changeMonth'=> 'true',

									'changeYear'=> 'true',

								),

								'htmlOptions'=>array(

									'style'=>'height:20px;'

								),

							));

							?>

							<b>to :</b>

							<?php

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

								'name'=>'to_date',

								 'options'=>array(

									'showAnim'=>'fold',

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

									'changeMonth'=> 'true',

									'changeYear'=> 'true',

								),

								'htmlOptions'=>array(

									'style'=>'height:20px;'

								),

							));

							?>

							<?php echo CHtml::submitButton('Search'); ?>

							<?php echo CHtml::submitButton('Reset'); ?>

							<?php $this->endWidget(); ?>

						</div><!-- search-form -->

						

						<div class="box-body table-responsive">

                            <?php

							$this->widget('zii.widgets.grid.CGridView', array(

								'id' => 'a-grid-id',

								'dataProvider' => $dataProvider,

								'columns' => array(


									array('name'=>'ID',

										'type'=>'raw',

										'value'=>'CHtml::link($data["ID"],array("controller/action","id"=>$data["ID"]))'

									), 

									array('name'=>'name',

										'type'=>'raw',

										'value'=>'$data["name"]'

									), 

								),

							));

							?>        

						</div>



please give me a solution

*sorry for my bad english

Your SQL should all be in a model method…

You also need to structure the query correctly:




$diagram1 = "SELECT * FROM table WHERE date BETWEEN '" . $from_date . "' AND '" . $to_date . "'";