Reputation: 4617
I have following table
myTable (id{INT},title{VARCHAR}, created{DATE(y-m-d)});
I am using following code to query the number of records that have been created with in this month using codeigniter's active records. But i am getting an error
$this->db->select('*');
$this->db->from('myTable');
$this->db->where('created=', Month(Date));
$query = $this->db->get();
return $query->num_rows();
My question is what is the correct way of doing this using CI active records. Could someone please help me.
Upvotes: 3
Views: 8396
Reputation: 1904
As you want to compare month only,you should take month(created
) in query rather than created
only.
$query = $this->db->query("SELECT * FROM `myTable` where month(`created`) = date('m')");
Check if this is working for you.
Upvotes: 8