title: Query database rows where timestamp column is older than X hours
body: <p>I have a bunch of rows in a MySQL database table, with a <em>last_update</em> (TIMESTAMP) field to log when they were last modified. As of right now, I loop through all of the rows every 300 seconds and check to see if 3+ hours have elapsed, and then update that row if so.</p>
  
  <pre><code>    $update_delay = 180;
  
      $table_name = $wpdb-&gt;prefix . "products";
      $results = $wpdb-&gt;get_results( "SELECT id, prod_id, last_update FROM $table_name" );
  
      foreach ($results as $result)
      {
          $last_update = $result-&gt;last_update;
  
          if (time() - strtotime($last_update) &gt; $update_delay * 60)
          {
  </code></pre>
  
  <p>As this is inefficient, I would like to query just the rows where the timestamp is older than 3 hours. Since that field has the format of "2020-03-01 23:22:06" I think I can do something like the following, but am not sure if I can do this using INTERVAL in the query, or if the date to check against should be in PHP.</p>
  
  <pre><code>$old_timestamp = date('Y-m-d G:i:s') . "- 3 hours";
  
  $results = $wpdb-&gt;get_results( "SELECT id, prod_id FROM $table_name WHERE last_update &gt; $old_timestamp" );
  </code></pre>
  
  <p>What would be a good option to implement this efficiently?</p>