I have a bunch of date data in a mysql table like this:
2010-02-13 1:00:00, \"soma data\"
2010-02-13 1:25:00, \"soma data\"
2010-02-13 1:37:00, \"soma data\"
You may want to use the GROUP BY
clause as in the following query:
SELECT
COUNT(*),
YEAR(dateTimeField),
MONTH(dateTimeField),
DAY(dateTimeField),
HOUR(dateTimeField)
FROM
yourTable
WHERE
dateTimeField >= '2010-02-04 00:00:00' AND
dateTimeField < '2010-02-14 00:00:00'
GROUP BY
YEAR(dateTimeField),
MONTH(dateTimeField),
DAY(dateTimeField),
HOUR(dateTimeField);
You may also want to check the MySQL documentation for further reference on date and time functions:
SELECT HOUR(datetime), COUNT(*)
FROM table
GROUP BY HOUR(datetime);
You will get two fields: the hour and the number of events during that hour.