Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP: Find records from last hour

Tags:

php

mysql

cakephp

I spent a good amount of time last night scouring the internet trying to find a solution to finding all of the records created from the last hour in the MySQL database. The one answer I found which is posted everywhere doesn't even work..

This is what I've come up with based on what I found online and thought might work:

$recentUploads = $this->Upload->find('all', array(
            'conditions' => array('Upload.created LIKE' => date('Y-m-d H:i:s', strtotime('-1 hour')))
        ));

But still no luck at all. Any thoughts?

like image 469
div Avatar asked Mar 22 '23 15:03

div


1 Answers

You want records where the timestamp is greater than or equal to the time 1 hour ago:

$recentUploads = $this->Upload->find(
  'all',
  array(
    'conditions' => array(
      'Upload.created >=' => date('Y-m-d H:i:s', strtotime('-1 hour'))
    )
  )
);
like image 108
ianmjones Avatar answered Mar 31 '23 19:03

ianmjones