necken18 Posted January 21, 2011 Share Posted January 21, 2011 Hello. I want to extract year and month from a datetime column in the database. And i want to display the results like this: 2008 Jan May 2010 Oct 2011 Dec But my code gets this result 2008 Jan May 2010 Oct 2011 Dec Here's my code. $get = $db->query(" SELECT EXTRACT(YEAR FROM date) year, EXTRACT(MONTH FROM date) month FROM test GROUP BY year "); foreach ($get as $row) { echo $row['year']."<br/>"; echo $row['month']."<br/>"; } } catch(PDOException $e) { echo $e->getMessage(); } Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 21, 2011 Share Posted January 21, 2011 See this link - http://www.phpfreaks.com/forums/mysql-help/need-some-array-help-bigtime!!!/msg1513324/#msg1513324 Obviously, you would need to change any usage of 'date' to 'year' to match what you are doing. Quote Link to comment 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.