Mysql 5 5 Now Bug
Consider the following query:
SELECT
COUNT(DISTINCT(mac)) AS total
FROM stats
WHERE sighting_time
BETWEEN DATE_SUB( NOW(), INTERVAL {period} SECOND) AND NOW();
If you are running MySQL < 5.6.12, you are golden. In 5.5.22, will return 0.
Solution:
CAST(NOW() AS char)
This query works:
SELECT
COUNT(DISTINCT(mac)) AS total
FROM stats
WHERE sighting_time
BETWEEN DATE_SUB( CAST(NOW() AS char), INTERVAL {period} SECOND) AND CAST(NOW() AS char);