title: How to group time intervals in php/mysql and get statistics based on those time groups?
body: <p>I am new to php and I have a problem with time/date manipulation.</p>
  
  <p>I need to make statistics about daily/monthly/yearly visits in some store.
  There is a mysql database with table "statistics" and <code>fields: "statistic_id" ( integer, primary key ) , "visitors" ( integer ), and "dateAndTime" ( timestamp )</code>. I have a form where user enter number of visitors that came to the store, and that number is inserted in database along with the time and date using now() function.</p>
  
  <p>So basically my database looks like : </p>
  
  <pre><code>statistic_id , visitors , timeAndDate &lt;br /&gt;
  1............, 3........., 2012-09-29 14:45:02 &lt;br /&gt;
  2............, 5........., 2012-09-29 14:46:31 &lt;br /&gt;
  3............, 2........., 2012-09-29 18:48:11 ...etc.
  </code></pre>
  
  <p>What I need to do is sum and display all visitors that came in specific time interval.
  <code>09h-12h ; 12h-15h ; 15h-18h ; 18h-21h</code> . So I need to display in table all these intervals and number of visitors for each of them. The problem is I don't know how to extract these intervals and then get sum of visitors for them. I was trying everything I know and I could find, but without success. Also I will have to get monthly and yearly statistics, so how can I get all <code>12 months</code> from this <code>timeAndDate</code> column and then <code>sum all visitors for each month</code> ?</p>
  
  <p>Do anyone have an idea how to do this, and is willing to explain me in details please ? Thanks</p>