//获取日期的控制器逻辑
function new temp()
{
$date= $this->Profile->find('all',array(
//'conditions'=>array('Profile.DOB+interval EXTRACT(YEAR FROM NOW())- EXTRACT(YEAR FROM Profile.DOB)YEAR >= '=>date('Y-m-d')),
'conditions'=>array('date(Profile.DOB+interval (EXTRACT(YEAR FROM NOW())- EXTRACT(YEAR FROM Profile.DOB))YEAR >= '=>date('Y-m-d')),
'fields'=>array('date(Profile.DOB+interval (EXTRACT(YEAR FROM NOW())- EXTRACT(YEAR FROM Profile.DOB))YEAR'),
'order' => 'date(Profile.DOB+interval EXTRACT(YEAR FROM NOW())- EXTRACT(YEAR FROM Profile.DOB))YEAR',
'limit'=>1
));
for each ($date as $new)
{
$one= $new['Profile']['DOB'];
}
$data= $this->Profile->find('all',array(
'conditions'=>array('date(Profile.DOB+interval (EXTRACT(YEAR FROM NOW())- EXTRACT(YEAR FROM Profile.DOB))YEAR) >= '=>date($one))
));
$this->set('one',$data);
}
请有人帮忙吗.....
这是获取适当日期的MySQL查询,与当前日期与表格中的日期进行比较..
select * from profiles
where
date(date(DOB+interval (year(now())-year(DOB)) year))=
(select (date(DOB+interval (year(now())-year(DOB)) year)) from profiles
where date(date(DOB+interval (year(now())-year(DOB)) year))>=date(now())
order by date(date(DOB+interval (year(now())-year(DOB)) year)) limit 1 );
答案 0 :(得分:0)
尝试此查询,它将根据日期和月份为您提供最新日期,之后您必须使用php日期函数将年份更改为当前年份。
$date= $this->Profile->find('first',array(
'fields'=>array('date(Profile.DOB)'),
'order' => 'day(Profile.DOB), month(Profile.DOB) DESC'
));
希望它能奏效!