Question

I'm wanting to get all the datetime column in my db but but it in a graph using Chart.js, now hard coding data in works fine but I want to know i can use my db datetime col to count how many sign ups happened is each month then return this to the graph, anyone know how to do this?

Currently when someone signs up it enters the date like: 2013-12-18 12:03:50

So I need to grab the months then post this to the graph :)

Was it helpful?

Solution

Just use MySQL MONTH() function, like:

SELECT MONTH(table.date) from table WHERE ...

In case you want to count the amount by month, so use the count function and group the query by MONTH(datetime). If you need help with this, please leave a comment.

For example, if you have a table that has a list of users, it will look something like that:

SELECT YEAR(register_date), MONTH(register_date) AS MONTH, COUNT(*) AS registered FROM users GROUP BY YEAR(register_date), MONTH(register_date) - this will give you the result of registered users count by year and month.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top