title: PHP MYSQL Select data from the last 24 hours and previous 24 hours
body: <p>So I have a script that stores data in a MYSQL database every hour and I am working on putting that data into a graph. I would like to make a graph with two lines. The first line would be data from the last 24 hours and the second line would be the data from the previous 24 hours.</p>
  
  <p>I have tried to query the database like this:</p>
  
  <pre><code>// this is for the first line in the graph
  "SELECT * FROM database WHERE date &gt;=(DATE_SUB(now(), INTERVAL 24 HOUR))";
  
  // this is for the second line in the graph
  "SELECT * FROM database WHERE date &gt;=(DATE_SUB(now(), INTERVAL 48 HOUR)) AND date &lt;=(DATE_SUB(now(), INTERVAL 24 HOUR))";
  </code></pre>
  
  <p>But the results aren't exactly correct.. I apologize if my MYSQL is nasty, I'm just learning it right now.</p>
  
  <p>Interestingly the above code did not provide me with all the data from the first 24 hours or the previous 24 hours, but when I change the query like so:</p>
  
  <pre><code>// this is for the first line in the graph
  "SELECT * FROM database WHERE date &gt;=(DATE_SUB(now(), INTERVAL 48 HOUR))";
  
  // this is for the second line in the graph
  "SELECT * FROM database WHERE date &gt;=(DATE_SUB(now(), INTERVAL 3 DAY)) AND date &lt;=(DATE_SUB(now(), INTERVAL 2 DAY))";
  </code></pre>
  
  <p>It appears to work for some strange reason?</p>
  
  <p>This is the format of my database:</p>
  
  <pre><code>id | data | date | time
  0  | 0.00 |Y-d-m |H:i:s
  </code></pre>
  
  <p>Right now it has about 68 entries.</p>
  
  <p>Can someone help me to understand this? Or recommend a better method? Thanks in advance!</p>