The first problem I only input from_date: 01-2015-01-01 and to_date: 05-02-2015, the result is the data from only 01 to 05 is appears. but if all parameter filled all (user,location,from_date, to_date) the seacrh result data with to_date(date 05-02-2015) is not appear, only date:01 until 04 appear.
The second problem if I input from_date and to_date same date (to search for one period) with parameter user_id and location filled all or not filled, no results found.
below model code :
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
if(!empty($this->from_date) && empty($this->to_date)){
$criteria->condition="create_date >= '$this->from_date'";
}elseif(!empty($this->to_date) && empty($this->from_date)){
$criteria->condition="create_date <= '$this->to_date'";
}elseif(!empty($this->to_date) && !empty($this->from_date)){
$criteria->condition="create_date >= '$this->from_date' and create_date<= '$this->to_date'";
}
//
$criteria->compare('user_id',$this->user_id);
$criteria->compare('location',$this->lokasi,
/* $criteria->mergeWith('create_date',$this->create_date
); */
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>array(
'defaultOrder'=>array('create_date DESC',)),
'pagination'=>array(
'PageSize'=>20
),
));
}
please help, how is the correct code for search with date range filter ?