riviraz
riviraz

Reputation: 479

MySQL group by day with TIMESTAMP column

I have a mysql table that has a column for "date time" in TIMESTAMP format. Is there a way to group the rows by day using that column? And in an SQL query, not grouping them in php.

Upvotes: 3

Views: 7727

Answers (3)

Jonathan Hall
Jonathan Hall

Reputation: 79584

If you mean you have a standard DATETIME column, you can group by using one of the functions described here.

For instance:

GROUP BY DATE(datetime_column);

If you actually have a TEXT or VARCHAR column (your answer doesn't specify), then you'll need to convert it to to a date first:

GROUP BY DATE(STR_TO_DATE(datetime_column));

Upvotes: 3

deceze
deceze

Reputation: 522081

Assuming your column is one of the Date and Time types:

SELECT ... GROUP BY DATE(`datetimecolumn`)

Upvotes: 8

Bill Karwin
Bill Karwin

Reputation: 562330

GROUP BY TO_DAYS(`datetime_column`)

Upvotes: 5

Related Questions