It worked yesterday.
It worked yesterday.

Reputation: 4617

Querying records created in this month using codeigniter

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

Answers (2)

Vali S
Vali S

Reputation: 1461

This will do:

 $this->db->where('month(created)', date('m'));

Upvotes: 9

CodeWithCoffee
CodeWithCoffee

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

Related Questions