title: GROUP BY day of Datetime SQL
body: <p>I'm making a Sales report by PHP. The transaction date and time is on column <code>LastUpdateTime</code> with format: <code>m-d-Y H:i:s</code>. Now I wanna make report for 1 week, so I need the sum of TotalAmount of all transaction in 1 day, so I use group by <code>DAY</code> of <code>LastUpdateTime</code>. Here is my code but it doesn't work:</p>
  
  <pre><code>&lt;?php
  include 'report/go.php'; //DB connect
                                      $today =time();
                                      $from_time = date('d-m-Y', strtotime('last Monday'));
                                      $to_time = date('d-m-Y', strtotime('next Monday - 1 MIN'));
      $sql = "SELECT 
              SUM(TotalAmount) AS TotalPerDay , LastUpdateTime, DATEPART(dd,LastUpdateTime)
              FROM Tickets
              WHERE LastUpdateTime BETWEEN '$from_time' and '$to_time'
              GROUP BY DATEPART(dd,LastUpdateTime)
              ";
      $stmt = sqlsrv_query( $conn, $sql );
          if( $stmt === false) 
              {
                  die( print_r( sqlsrv_errors(), true) );
              }
          while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) 
              {
                  $money = $row['TotalPerDay'];
                  $date = date_format($row['LastUpdateTime'], "d-m-Y");
                  echo $money." - ".$date."&lt;br&gt;";
              }
  ?&gt;
  </code></pre>
  
  <p>Error returned:</p>
  
  <blockquote>
    <p>Column 'Tickets.LastUpdateTime' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause</p>
  </blockquote>
  
  <p>Please help :) Thank you so much :)</p>