I'm trying to get all data which date is greater than or equal to today.
Here is what I do:
$this->db->select('id, name');
$this->db->where('dr', '1');
$this->db->where('end >=', 'CURDATE()');
$query = $this->db->get('store');
But it doesen't work. What I wrong ?
Active Records automatically escapes your query, so CURDATE() will be passed as a string instead of using the mysql function.
You'd better off runing your query manually, something like
$query = $this->db->query("SELECT id,name FROM store WHERE dr = '1' AND end >= CURDATE()");
Or if you still want to use AR, you could pass a FALSE as third parameter of $this->db->where
to avoid automatic escaping by CI:
$this->db->select('id,name')
->where('dr','1')
->where('end >=', 'CURDATE()', FALSE);
$query = $this->db->get('store');
I don't use active records in CI but I would guess that CURDATE()
is being put in a string in the query so it's doing WHERE end >= 'CURDATE()'
as opposed to WHERE end >= CURDATE()
If end
is a timestamp field try...
$this->db->where('end >=', time());
If end
is a datetime field try...
$this->db->where('end >=', date("Y-m-d H:i:s"));