使用 mysql 或 cakephp 的月份搜索结果

search result in month using mysql or cakephp

大家好我有一个问题搜索结果月使用 MySql 或 Cakephp 我的 table 名字是 state_supplies 和数据是

MySql查询是:

SELECT * FROM `state_supplies` WHERE created=DATE_FORMAT(NOW(), '%m')

Cakephp搜索代码为

$this->StateSupply->find('all', array(
                      'conditions'=> array(
                        'unitid'=>$this->Session->read('Auth.User.unitid'),
                        'created'=>'MONTH(CURDATE())'
                      )                 
                    )
);

试试这个:

在Mysql中:

$first_day_this_month = date('Y-m-01 H:i:s'); // hard-coded '01' for first day
$last_day_this_month  = date('Y-m-t H:i:s');
$sql="SELECT * FROM state_supplies WHERE created between '$first_day_this_month' and '$last_day_this_month' "

Cakephp代码

Details

更新正确答案的代码

 $this->StateSupply->find('all',array(
                'conditions'=>array(
                    'unitid'=>$this->Session->read('Auth.User.unitid'),
                    'crop'=>$this->request->data['StateSupply']['crop'],
                    'state'=>$this->request->data['StateSupply']['state'],
                    'created BETWEEN ? AND ?'=>array(date('Y-m-01',strtotime('this month')),date('Y-m-t',strtotime('this month')))
                        )                   
                    )
                );