Because I can not filter by date, Codeigniter

0

Now try using:

1.-
    $this->db->where('a.fecha >= "'.$date1.'"');
    $this->db->where('a.fecha <= "'.$date2.'"');
2.-
    $this->db->where('DATE(a.fecha)',$date2);
3.-
$this->db->where('a.fecha',date('Y-m-d',strtotime($date1))); ....

If directly in mysql I put:

SELECT * FROM 'entrada' where fecha >= "2018-07-14" and fecha <= "2018-07-14"

works perfectly for me, showing information.

I do not understand why it does not work for me using codeigniter in any way.

    
asked by DoubleM 15.07.2018 в 04:12
source

1 answer

2

If you check the Query Builder documentation you'll see that there are several ways to pass the parameters:

  • Putting where followed by one another, but without trying to build the criterion chain. You only have to pass the condition (to the left) and the variable (to the right), both parameters separated by a comma. And, of course, you must ensure that the variables are valid dates, otherwise it will not work:

    $this->db->where('a.fecha >= ',$date1);
    $this->db->where('a.fecha <= ',$date2);
    
  • You can pass the parameters in an associative array where each key would be the criterion and the each value the data that will be used in the criterion:

    $array = array('a.fecha >=' => $date1, 'a.fecha <=' => $date2);
    $this->db->where($array);
    
  • answered by 15.07.2018 в 05:17