Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bottelet's avatar

Get the month from date, and how many tasks created that month?

Hello Laracasts

So this a bit of a broad question, I'm trying to build a statics of how many tasks is created one month with ChartJS, So what i need is to get the Created_at months value, from the Tasks table, and somehow form all of thoose into an array, and see how many tasks have been created within each month. I have to admit i'm not sure how to handle this, and need some guideance in the right path.

Hope someone can spark some light on to this problem for me.

0 likes
2 replies
willvincent's avatar

Ultimatley the query you're going to want would be essentially this...

SELECT
   DATE_FORMAT(record_date, '%m/%Y') AS month_year, 
   COUNT(id) AS total 
FROM tasks 
GROUP BY month_year

That'll give you output like this:

month_year | total
-----------+------
01/2016    | 16
02/2016    | 12
03/2016    | 22

If you just want by month, not month and year, omit the /%Y in the date_format.

Please or to participate in this conversation.