如何在cakephp中以时间间隔从数据库获取前一天的数据?

时间:2012-09-29 09:31:58

标签: mysql cakephp

我试试这个,但它不起作用

{
'conditions' => array('Graph.hid' => $hid, 'DATE(Graph.created) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)', 'Graph.number'=>2)
}

实际上需要前一天的当前时间数据。 谁能帮我?提前谢谢。

1 个答案:

答案 0 :(得分:1)

如果您有DATETIME,可以在查询中找到BETWEEN(find):

$yesterday = date("Y-m-d", (time()-86400));
$query = 'SELECT * FROM table WHERE registration between '."'$yesterday 00:00:00'".' and '. "'$yesterday 23:59:59'"; 
蛋糕之间是:

array('Post.read_count BETWEEN ? AND ?' => array(1,10))

计算最后一天的其他方法:

date("Y-m-d", time() - 86400);
date("Y-m-d", strtotime("yesterday")); 
date("Y-m-d", strtotime("-1 day"));