I had a mysql table called events with fields: id, date and name. The date field has the format yyyy-mm-dd hh :: mm: ss edit: means that it is in the datetime format
I want to group events per day, and I was not sure how to approach this - is there a way to select only a month and a day from the field? or should I use PHP after selecting all the "events"
my ultimate goal is to have something like this:
March 10th: event1, event2 March 11th: event4, event5
I found MySQL using datetime, only by date , but I'm not sure how to implement it:
SELECT DATE_FORMAT(date, '%H%i'), DATE_FORMAT(date, '%M %D'), name FROM events ORDER BY date
Thanks!
EDIT:
finished using this:
$sql = "select team1, team2, DATE_FORMAT(date,'%Y-%m-%d') as created_day FROM games WHERE attack = '1' GROUP BY created_day"; $result = mysql_query($sql); $curDate = ""; while (list($team1, $team2, $date) = mysql_fetch_row($result)) { if ($date != $curDate) { echo "$date --------\n"; $curDate = $date; } echo "game data: $team1 $team2"; }
source share