MySQL: GROUP BY on DATETIME field

This item was filled under [ MySQL ]

Often webmasters want to sort out data on the basis of Dates when timestamp is stored as datetime in MySQL. To obtain the desired result, simply query:

SELECT DATE_FORMAT(MyDate, '%d %M %Y') AS Date, COUNT(*) AS numRows FROM Table1 GROUP BY Date;

Rate this topic:
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Popularity: 158 views
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

4 Comments on “MySQL: GROUP BY on DATETIME field”

  • Mrtn
    18 May, 2008, 16:48

    coool.. learned somethng new today :) thanks

  • 16 August, 2008, 20:20

    awesome!!! exactly what I needed…

  • 26 September, 2008, 16:51

    A big thank to you!

  • appreciated
    7 October, 2008, 2:39

    Very helpful thank you.

Leave a Comment