Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL GROUP BY date when using datetime

In MySQL, let's say I have a table with a column called 'actionTime' declared as a 'datetime' (YYYY-MM-DD HH:MM:SS).

Is there an easy way to use "GROUP BY actionTime" but only use the 'date' part of the 'datetime'?

Thanks

like image 344
Nathan H Avatar asked Dec 16 '09 22:12

Nathan H


2 Answers

Should be able to

GROUP BY date(actionTime)

See this for more info.

like image 151
Benjamin Cox Avatar answered Nov 04 '22 02:11

Benjamin Cox


Ahh Google .. so easy to use.
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date

mysql> SELECT DATE('2003-12-31 01:02:03');
        -> '2003-12-31'
like image 36
BryanD Avatar answered Nov 04 '22 01:11

BryanD