How to Group Data Month when Using Datetime Column MySQL >

Asked By 10 points N/A Posted on -
qa-featured

I'm running MySQL and I have a table titled Datetime in YYYY-MM-DD HH:MM:SS format. How can I group the Data Month on Datetime Column?

SHARE
Answered By 0 points N/A #125118

How to Group Data Month when Using Datetime Column MySQL >

qa-featured

Try this:

GROUP BY date(ActionTime) or:

Assuming you store the date and time under the datetime column, to query it you want to count the results according to group by date, below is the format:

SELECT DATE_FORMAT(postdate, '%Y-%m-%d') AS dd, COUNT(id) FROM MyTable GROUP BY dd;

Or you can also try the upgraded query and use the string below:

SELECT substring(postrdate, 1,10) AS dd, COUNT(id) FROM MyTable GROUP BY dd;

This works faster than the first, but whichever works for you, will do.

For more information, click the link below:

Commands on MySQL Date and Time Functions

Related Questions