title: MySql Query For Date Range in PHP
body: <p>I have a MySql database that uses a timestamp field to track when the entry was inserted.</p>
  
  <p>Now I want to query the table for entries by a date range.</p>
  
  <p>I would prefer to use MySql to extract the records instead of extracting all records then iterating and comparing dates in php.</p>
  
  <p>So I have a start-date and an end-date. I have tried YYYYMMDD and YYYY-MM-DD format with no success on these two kinds of queries:</p>
  
  <pre><code>// this doesn't appear to be working
  SELECT COUNT(*) FROM table_name 
  WHERE DATE(timestamp_row) BETWEEN '{$date1}' AND '{$date2};
  
  // this doesn't appear to be working either
  SELECT COUNT(*) FROM table_name 
  WHERE DATE(timestamp_row) &gt;= {$date1}
  AND DATE(timestamp_row) &lt;= {$date2};
  </code></pre>
  
  <p>It appears that the Mysql DATE() function turns the timestamp into this format:
  YYYY-MM-DD</p>
  
  <p>Is there a way to do this.</p>