如何从cakephp查询中获取日期

时间:2013-12-20 11:35:09

标签: php cakephp

$date= $this->Profile->find('all',array(

              'conditions'=>array('date(Add date(DOB,interval (year(curdate())-year(DOB)) year))>=date(now())'),
              'fields'=>array('date(Add date(DOB,interval (year(curdate())-year(DOB)) year)'),

              'limit'=>1,
              'order'=>'date(Add date(DOB,interval (year(curdate())-year(DOB)) year))'
          ));

任何人都可以帮助我....

MySQL查询:

(select date(Adddate(dob,interval (year(curdate())-year(dob)) year)) 
from profiles
where date(Adddate(dob,interval (year(curdate())-year(dob)) year))>=date(now()) 
order by date(Adddate(dob,interval (year(curdate())-year(dob)) year)) limit 1 );

1 个答案:

答案 0 :(得分:0)

确保您的条件数组声明如下:

'conditions' => array('field >=' => $value) // when condition is >=
'conditions' => array('field <=' => $value) // when condition is <=
'conditions' => array('field' => $value) // when condition is =

如果它不起作用,也许你应该使用custom queries而不是find函数。