我昨晚花了很多时间在网上搜索,试图找到一个解决方案,找到MySQL数据库中最后一小时创建的所有记录。我找到的一个答案在任何地方发布都不起作用..
这是我根据我在网上找到的内容而想出来的,并且可能会有所作为:
$recentUploads = $this->Upload->find('all', array(
'conditions' => array('Upload.created LIKE' => date('Y-m-d H:i:s', strtotime('-1 hour')))
));
但仍然没有运气。有什么想法吗?
答案 0 :(得分:6)
您需要时间戳大于或等于1小时前的记录:
$recentUploads = $this->Upload->find(
'all',
array(
'conditions' => array(
'Upload.created >=' => date('Y-m-d H:i:s', strtotime('-1 hour'))
)
)
);
答案 1 :(得分:0)
您需要使用此功能的任何时间:
function SinceDate($timebyminuites)
{
$to_time = strtotime(date('Y-m-d H:i:s'));
$from_time = $timebyminuites*60;
return date('Y-m-d H:i:s',round(abs($to_time - $from_time),2));
}
当你想要从一小时前获得日期时间 你可以使用这样的功能:
$onehoursago = SinceDate(60);
,查询将如下:
select * from Upload where Upload.created >= '$onehoursago'