Jump to content

Archived

This topic is now archived and is closed to further replies.

webbgroup

Tricky 'GROUP BY' MySQL question

Recommended Posts

How would you group by dates in a table where the date shows up like this: \"2003-01-15 13:05\"

 

I already tried something like this without much success.

 

select time as TIME, count(*) as posts from table group by time REGEXP \"2003-01-%\";

 

Any suggestions??

Share this post


Link to post
Share on other sites




mysql> SELECT DATE_FORMAT(\'1997-10-04 22:23:00\', \'%Y-%m-%d\');

+------------------------------------------------+

| DATE_FORMAT(\'1997-10-04 22:23:00\', \'%Y-%m-%d\') |

+------------------------------------------------+

| 1997-10-04                                     |

+------------------------------------------------+

1 row in set (0.00 sec)



mysql> 



 

Use the date_format consistently throughout the query.

 

I think you should read the mysql manual about date functions:

 

http://www.mysql.com/doc/en/Date_and_time_..._functions.html

 

P., denmark

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.