Q:

How does one tell if a new month has started? php/mysql

I have the dates stored in a mySQL table from 2010 - 2040 in the following format:
2012-01-02
I SELECT each date from the table and display them in a while - mysql_fetch_assoc loop
while($row=mysql_fetch_array($result)){

    echo $row["date"];

}

how can I check that a new month has started?  I suspect I need to place the current month counter in a var using explode()... but how can a comparison be made since the var will be overwritten in the while loop
if(old month != new month){
    do something..
}

thanks

A:

$old_month = '';

while($row=mysql_fetch_array($result)){
  list($year, $month, $day) = explode('-', $row["date"]);
  if($old_month != $month) {
    $old_month = $month;
    echo 'new month';
  }
}

