title: Magento group by clause on date field
body: <p>I need to fetch total number of order, SUM,MIN MAX and AVG of 'grand_total' in a day for a specified month. This is what I am doing.</p>
  
  <pre><code>$collection-&gt;getSelect()
                 -&gt;columns( 'SUM(base_grand_total) AS total' )
                 -&gt;columns( 'COUNT(*) AS orders_count' )
                 -&gt;columns( 'DATE_FORMAT(created_at, "%d") AS order_day' )
                 -&gt;columns( 'DATE_FORMAT(created_at, "%d/%m/%y") AS order_date' )
                 -&gt;columns( 'AVG(base_grand_total) AS avg_total' )
                 -&gt;columns( 'MAX(base_grand_total) AS max_total' )
                 -&gt;columns( 'MIN(base_grand_total) AS min_total' )
                 -&gt;where( 'DATE_FORMAT(created_at, "%m") = ?', $month )
                 -&gt;where( 'DATE_FORMAT(created_at, "%Y") = ?', $year )
                 -&gt;group( 'DATE_FORMAT(created_at, "%d-%m-%y")' );
  </code></pre>
  
  <p>$month is "Sep" and $year is "2014"</p>
  
  <p><img src="https://i.stack.imgur.com/D8pxc.png" alt="Current Output for the above query on Custom Grid System"></p>
  
  <p><img src="https://i.stack.imgur.com/5nBZS.png" alt="what Sales &gt; Order says for same time period "></p>
  
  <p>Above query says that there are 3 orders on 26th, but magento's Sales > Order grid says only one order is there for 26th. I guess the answer lies within, 
  "<strong>created_at</strong>" stored as "2014-09-04 02:50:04" in DB, but if we format this its comes to "Sep 3, 2014 4:50:04 PM".</p>
  
  <p>So, can anyone suggest how to apply group by date clause on Collection.</p>
  
  <p>Thanks in Advance.</p>