I am new to php and I have a problem with time/date manipulation.
I need to make statistics about daily/monthly/yearly visits in some store.
There is a mysql database with table "statistics" and fields: "statistic_id" ( integer, primary key ) , "visitors" ( integer ), and "dateAndTime" ( timestamp )
. 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.
So basically my database looks like :
statistic_id , visitors , timeAndDate <br />
1............, 3........., 2012-09-29 14:45:02 <br />
2............, 5........., 2012-09-29 14:46:31 <br />
3............, 2........., 2012-09-29 18:48:11 ...etc.
What I need to do is sum and display all visitors that came in specific time interval.
09h-12h ; 12h-15h ; 15h-18h ; 18h-21h
. 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 12 months
from this timeAndDate
column and then sum all visitors for each month
?
Do anyone have an idea how to do this, and is willing to explain me in details please ? Thanks