1

Here i want to get the result based on the dates that i would like to give but returning back the entire results the databse looks like this

the databse looks like this

customer_account_id     customer_id     date           code     
    11                    55         01-01-2017     ALI HAJI        
    12                    55         02-01-2017     ALI HAJI                
    13                    55         03-01-2017     ALI HAJI                
    125                   65         01-02-2017     SHARFU              
    126                   55         02-02-2017     ALI HAJI        
    127                   55         03-02-2017     ALI HAJI            
    128                   55         31-01-2017     ALI HAJI

controller looks like this

 public function report()
{
    $data['result']= $this->Account_model->get_report($_POST['from_date'],$to1['to_date'])->result();
    $this->load->view('report_payment_details',$data);

}

my model looks like this

public function get_report($from1,$to1)
{

$from=date('d-m-Y',strtotime($from1));
var_dump($from);
$to=date('d-m-Y',strtotime($to1));
var_dump($to);  
$this->db->order_by('customer_account_id','desc');
$this->db->where('date >=', $from);
$this->db->where('date <=', $to);       
return $this->db->get('customer_accounts');

}

Here if i choose the dates between 01-01-2017 and 03-01-2017 then also the entire results will be displayed.The problem is only the first two values is considering from the date for example if i consider 01-01-2017 here only 01 is considering and remaining not.please help me to solve this

user_777
  • 845
  • 1
  • 9
  • 25

1 Answers1

2

If you want to stick with the VARCHAR maybe you can try using STR_TO_DATE

$from=date('d-m-Y',strtotime($from1));
var_dump($from);
$to=date('d-m-Y',strtotime($to1));
var_dump($to);  
$this->db->order_by('customer_account_id','desc');
$this->db->where("STR_TO_DATE(`date`,'%d-%m-%Y') >=", "STR_TO_DATE('".$from."','%d-%m-%Y')");
$this->db->where("STR_TO_DATE(`date`,'%d-%m-%Y') <=", "STR_TO_DATE('".$to."','%d-%m-%Y')"); 
return $this->db->get('customer_accounts');