therealwesfoster Posted October 29, 2008 Share Posted October 29, 2008 How can I group rows by their day of the month? Example: craigslist.com Table name: posts Date column: post_date How can I go about doing this? thanks Quote Link to comment https://forums.phpfreaks.com/topic/130641-group-rows-by-day/ Share on other sites More sharing options...
Mchl Posted October 29, 2008 Share Posted October 29, 2008 What's the format you keep post_date in? Quote Link to comment https://forums.phpfreaks.com/topic/130641-group-rows-by-day/#findComment-677859 Share on other sites More sharing options...
therealwesfoster Posted October 29, 2008 Author Share Posted October 29, 2008 As a unix timestamp Quote Link to comment https://forums.phpfreaks.com/topic/130641-group-rows-by-day/#findComment-677861 Share on other sites More sharing options...
corbin Posted October 29, 2008 Share Posted October 29, 2008 If it were a datetime type it would be easier. The first thing that comes to mind is: SELECT * FROM posts GROUP BY DAY(FROM_UNIXTIME(post_date)), MONTH(FROM_UNIXTIME(post_date)), YEAR(FROM_UNIXTIME(post_date)); That would be HORRIBLY slow though. Quote Link to comment https://forums.phpfreaks.com/topic/130641-group-rows-by-day/#findComment-677876 Share on other sites More sharing options...
therealwesfoster Posted October 29, 2008 Author Share Posted October 29, 2008 Thanks, but we want to avoid "horribly slow". So if I were to change the column type to "datetime" it would be faster? How would I access the date using PHP and still be able to use date()? Wes Quote Link to comment https://forums.phpfreaks.com/topic/130641-group-rows-by-day/#findComment-677879 Share on other sites More sharing options...
Mchl Posted October 29, 2008 Share Posted October 29, 2008 Use DATETIME or TIMESTAMP types to store datetime data. You just need to reformat date() function so that it's compatible with mysql format. Quote Link to comment https://forums.phpfreaks.com/topic/130641-group-rows-by-day/#findComment-677885 Share on other sites More sharing options...
corbin Posted October 29, 2008 Share Posted October 29, 2008 http://lists.mysql.com/mysql/183242 I think that pretty much answers your questions. Found it pretty interesting for me to read too. Quote Link to comment https://forums.phpfreaks.com/topic/130641-group-rows-by-day/#findComment-677943 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.