title: selecting records in mysql db from 1, 7, and 30 days ago with datetime and php
body: <p>Im using the following query to target results that are exactly X days older than current time.</p>
  
  <pre><code>SELECT  *,
          DATE_FORMAT(datetime, '%m/%d/%Y') 
     FROM table 
    WHERE datetime BETWEEN SYSDATE() - INTERVAL 30 DAY 
                       AND SYSDATE() 
  ORDER BY ID DESC
  </code></pre>
  
  <p>Problem is its returning data from current day if a record from exactly 30 days ago doesnt exist, as well as irrelevant data</p>
  
  <p>is there a better way of doing this?</p>