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(); } Link to comment https://forums.phpfreaks.com/topic/225170-extract-and-group-by-year/ 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. Link to comment https://forums.phpfreaks.com/topic/225170-extract-and-group-by-year/#findComment-1162913 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.