I am trying to filter the count of Rows found, per hour, over the past 24 hours.
I am using the following SQL query and ‘landtime’ is a DateTime field.
SELECT HOUR(landtime) as hour, COUNT(*) as total FROM ord_log WHERE landtime > DATE_SUB(NOW(), INTERVAL 24 HOUR) GROUP BY HOUR(landtime) ORDER BY HOUR(landtime)
Sample data set > http://pastebin.com/0rYBnePG
The results looked as expected, until I looked at the data it was using.
It was pulling dates from days/weeks before todays date when I only want a count for the past 24 hours.
Any help appreciated!
No need to use a function, just use simple math: