title: SQLite3 and PHP: sorting entries by datetime
body: <p>I have a SQLite3 DB with entries storing sensor readings. Each row in the table looks like this:</p>
  
  <pre><code>time                | temp1 | humid1 | temp2 | humid2
  2013-12-07 23:15:51 | 26.06 | 16.29  | 22.24 | 17.55
  </code></pre>
  
  <p>where the first entry is the date, and the following ones are sensor data.
  Now what I need to do is, using PHP, get the most recent 30 minutes of readings. I only want data that's less than 30 minutes old, since it's possible that data collection wasn't running and I would then get old data if I just selected the first bunch of values.</p>
  
  <p>I can think of 2 ways I could do this:
  Is there some way in SQLite to do something like this?</p>
  
  <pre><code>SELECT * FROM table WHERE time &lt; (time-30 minutes)
  </code></pre>
  
  <p>The other thing I could do is grab the first 300 values (equivalent to 30 minutes)
  and then compare the year, month, day, hour, and minute myself. The problem is, I don't know how to extract those from the PHP variable I get when I do just</p>
  
  <pre><code>SELECT * FROM table  ORDER BY time DESC limit 300
  </code></pre>
  
  <p>So let's say I get a row (in PHP) called $row, where the time is $row['time'].
  How would I go about extracting the years, months... etc. from that and comparing it to the current time?</p>