user765368
user765368

Reputation: 20346

using sql MONTH or YEAR in cakephp find queries

I'm trying to get all the users that has registered during a particular month using a query like this in a cakephp application:

$registered_users = $this->User->find('all', array(
    'conditions' => array(
        'MONTH(User.date)' => 10
    )
));

The query above is supposed to return me all the users that has registered during the month of october for example, but for some reason, I get the following error:

1054: Unknown column 'User.date' in 'where clause'

Does anybody know why I'm getting this error please?

Thank you

Upvotes: 0

Views: 3758

Answers (2)

Moyed Ansari
Moyed Ansari

Reputation: 8461

Try this

$condition['MONTH(date) >'] = '10';
$registered_users = $this->User->find('all', array(
    'conditions' => $condition,
));

Upvotes: 4

sethathi
sethathi

Reputation: 23

Sorry I dont have enough points to add this as a comment.

Make sure in your database User.date column actually exists. Maybe you wanted to use User.created?

Upvotes: 0

Related Questions