我对我在CakePHP中所做的一个问题有疑问。我需要从我的数据库中获取所有记录,具体取决于粗略日期的小时差异。例如:
$date = 2015-10-15 11:10:59;
我需要计算$data['Inscripcion']['date']
和$date
之间相隔四个小时或更长时间,否则不应该带来记录数据库。这一切都在find->('list', array('conditions => array('date')))
.
但它不能认为我在同一查询中包含数据的值
不确定你想做什么,但是
if (abs(strtotime($date) - strtotime($data['Inscripcion']['date'])) > (60 * 60 * 4)) {
// stuff
}
编辑:对不起,我已经习惯了PHP 5.3,请参阅nessuno的答案。
您可以使用
PHP内置类:DateTime
和DateInterval
$date = new DateTime('2015-10-15 11:10:59');
$date2 = new DateTime($data['Inscripcion']['date']);
$diff = $date2->diff($date);
if($diff->h + $diff->days*24 > 4) {
//do stuff
}