Chartjs-Retrieving daily & monthly totals from MySQL for use in a chart

1👍

You could use function TIMESTAMPDIFF(), for example:

SELECT TIMESTAMPDIFF(DAY, created, NOW()) AS days, COUNT(*) AS num
FROM subscribers
WHERE created > DATE_SUB(NOW(), INTERVAL 3 MONTH)
GROUP BY days 
ORDER BY days ASC

I have just runed this query on 2 million record table, and it is fast.

If you wish to explode days in 7, 30, 90 etc. days, simply do it with PHP.

Leave a comment