The only easy way to achieve this is to have a *SEPARATE* calendar
table that has EVERY DATE (in you expected date range) in it.
CREATE TABLE calendar (
theDate DATE PRIMARY KEY
and then the contents of that table are just
And now it is easy:
SELECT C.theDate, IFNULL( COUNT(*), 0 ) AS countForDate
FROM calendar AS C LEFT JOIN history AS H
ON C.theDate = DATE( CAST( H.timeentry AS DATE ) )
WHERE YEAR(C.theDate) = YEAR(NOW()) AND MONTH(C.theDate) = MONTH(NOW())
GROUP BY C.theDate
ORDER BY C.theDate
The WHERE clause can of course pick any range of date you want. Such as
WHERE C.theDate BETWEEN '2012-9-1' AND '2012-12-31'
You can use a STORE PROCEDURE to create a TEMPORARY TABLE with the required range of dates (and then end the PROCEDURE with a SELECT * from the temporary table), but (a) you need to be good at stored procedures to make it efficient, (b) if you change your mind about WHAT you are selecting you have to rewrite the procedure, and (c) it's nowhere near as fast.
SO it's worth the time to create your CALENDAR table, as above. You only have to do it once. I have one I created in 2003 that I am still using today, even after migrating it from another DB (from Access, as a matter of fact). And I find more and more uses for it.