Cakephp 在日期范围内查找

Cakephp 在日期范围内查找,cakephp,date-range,cakephp-2.3,Cakephp,Date Range,Cakephp 2.3,我试图找到每个客户每月提供的所有服务。 根据回答的问题,我在总结中创建了以下代码: public function view($id=null) { //other code $this->loadModel('Event'); $summary = $this->Summary->find('first', array('conditions' => array('Summary.id'

我试图找到每个客户每月提供的所有服务。 根据回答的问题,我在总结中创建了以下代码:

      public function view($id=null) {
            //other code
            $this->loadModel('Event');
            $summary = $this->Summary->find('first', array('conditions' => array('Summary.id' => $id)));
            $first = date('m-01-Y', strtotime($summary['Summary']['date']));

            //added this for debugging and the value is the date i want
            $this->set('first', $first);

            $last = date('m-t-Y', strtotime($summary['Summary']['date']));

            //debugging, this works too
            $this->set('last', $last);

            $conditions = array("'Event.start' >=" => $first, "'Event.start' <=" => $last,
                                'Event.customer_id' => 'Summary.customer_id'
                               );
            $this->set('events', $this->Event->find('all', array('conditions' => $conditions)));
公共函数视图($id=null){
//其他代码
$this->loadModel('Event');
$summary=$this->summary->find('first',array('conditions'=>array('summary.id'=>$id));
$first=日期('m-01-Y',标准时间($summary['summary']['date']);
//添加了这个用于调试,值是我想要的日期
$this->set('first',$first);
$last=date('m-t-Y',strottime($summary['summary']['date']);
//调试,这也有效
$this->set('last',$last);

$conditions=array(“'Event.start'>=”=>$first,“'Event.start'您正在向查询中添加更多的单引号将不起作用

请将以下内容更改为$conditions

 $conditions = array("Event.start >=" => "'".$first."'", "Event.start <=" => "'".$last."'",
                                'Event.customer_id' => 'Summary.customer_id'
                               );

所以你可以比较日期。哦,也许你知道了。event.start的格式是datetime,summary.date只是一个日期。我会尝试将它改为datetime,修改代码,然后让你知道。修改如下:
$first=date('m-01-Y H:I:s',strotime($summary['summary']['date']);
但尝试调试这个
strotime('Event.start')
哪个结果为假…请在此处添加您的摘要日期,您也必须将其更改为$last中的日期。我已更新我的答案,以便在您的查询中使用日期。请让我知道
$summary['Summary']['date'] = '4-5-2013'; // where format is 'd-m-Y';

$first = date('m-01-Y H:i:s', strtotime($summary['Summary']['date']));

echo "first".$first;
echo "<br>date is -> ". date('m-t-Y');
first05-01-2013 00:00:00
date is -> 05-31-2013