Reputation: 4516
How to count/group data from array into hours from MySQL timedate format or unix timestamp?
My array:
Array (
[0] => Array (
[0] => id
[1] => name
[2] => 2013-01-10 00:36:00
)
[1] => Array (
[0] => id
[1] => name
[2] => 2013-01-10 00:36:00
)
)
How to shrink thousands of items like this and agregate them somehow to hours or even days? I just need rough number of rows with given hour in specyfic day.
Upvotes: 0
Views: 396
Reputation: 4516
Valid code for my case from answer from @Robert Seddon-Smith:
SELECT id
, name
, day
, key
FROM table
WHERE day > '2013 6-01 00:00:00' && day < '2013-6-31 23:59:59'
GROUP BY YEAR(day), MONTH(day), DAY(day), HOUR(day), SECOND(day)
Upvotes: 1
Reputation: 1002
try SELECT * from table GROUP BY HOUR(date_column) WHERE condition...
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_hour
Upvotes: 0