max
max

Reputation: 331

Count and group by day MySQL query

How can i count and group by day in MySQL. My issue is that I'm not using a MySQL time stamp.

I'm saving my date in below format

date("F j, Y");

So the date will be November 24, 2015, November 25, 2015, November 26, 2015 etc.

Can i keep the format as it is and count and group by day?

Upvotes: 0

Views: 132

Answers (1)

Shadow
Shadow

Reputation: 34232

The answer is - technically - yes, you can groupy by day and keep this format using mysql's str_to_date() function to convert your string to a date type and extract the day part out of it using one of the day related functions.

The question is, why would you do this? You should store the date either in a timestamp or datetime column and format the dates to your specification when you query it using date_format() function. This way you can retrieve the dates in the desired format and you retain the ability to easily perform date arithmetic within your sql code.

Upvotes: 3

Related Questions