Reputation: 3847
How can I find the Users that are "last_seen" the last 24hours?
[User][last_seen] => 2012-08-18 08:10:31
last_seen is updated each time a logged in user browse the website with current timestamp
This is what I have tried this far:
$users = $this->User->find('all',array('conditions'=>array('User.last_seen >' =>'BETWEEN NOW() AND NOW()- INTERVAL 24 HOURS'),'recursive'=>-2));
But my array is coming back empty.
Suggestions??
As always!! You are awesome! Thanks for your time!
-Tom
Upvotes: 2
Views: 3216
Reputation: 3847
Solution:
$users = $this->User->find('all', [
'conditions' => [
'User.last_seen BETWEEN NOW() -INTERVAL 1 DAY AND NOW()'
]
);
Upvotes: 4
Reputation: 21
Try this:
$users = $this->User->find('all', array(
'conditions' => array(
'User.last_seen BETWEEN ? AND ?' => array(
date('Y-m-d H:i:s'),
date('Y-m-d H:i:s', strtotime('+24 hours'))
)
)
));
Upvotes: 1