title: PHP: Format and sort the dates from MySQL Database
body: <p>I have these mysql dates in a table of my database,</p>
  
  <pre><code>2010-07-16 20:09:06
  2010-08-16 20:19:43
  2010-10-18 16:57:19
  2009-09-18 16:57:42
  2009-10-18 16:57:55
  2009-12-24 14:59:21
  </code></pre>
  
  <p>How can I sort them into the result below so that I can have the end user browses monthly results? </p>
  
  <pre><code>&lt;h2&gt;2010&lt;/h2&gt;
  &lt;ul&gt;
   &lt;li&gt;&lt;a href="#"&gt;October&lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href="#"&gt;November&lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href="#"&gt;December&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  
  &lt;h2&gt;2009&lt;/h2&gt;
  &lt;ul&gt;
   &lt;li&gt;&lt;a href="#"&gt;September&lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href="#"&gt;October&lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href="#"&gt;November&lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href="#"&gt;December&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>can't think of anything! </p>
  
  <p>I usually use gmdate() to format the dates from mysql database, for instance,</p>
  
  <pre><code>&lt;?php
   $sql = "
   SELECT *
   FROM root_pages
  
   WHERE root_pages.pg_hide != '1'
  
   ORDER BY pg_created DESC";
  
  #instantiate the object of __database class
  $object_items = new __database(DB_HOST,DB_USER,DB_PASS,DB_NAME);
  $items = $object_items -&gt; fetch_all($sql);
  
  echo  gmdate('j/n/Y', strtotime($item['pg_created']));
  ?&gt;
  </code></pre>
  
  <p>it would great if you can give me some hint to start!</p>
  
  <p>thanks,
  Lau</p>