title: SQL Server Group By X hours/days/weeks
body: <p>I was wondering how you would be able to group records by X days (and the other supported <code>DATEPART</code> periods).</p>
  
  <p>I have found two ways to group by one day/month/... using the following queries:</p>
  
  <pre><code>/** Group by one day method 1 **/
  SELECT 
      SUM(Id) AS Id, 
      DATEADD(DAY, 0, DATEDIFF(DAY, 0, DateTime)) AS DateTime 
  FROM 
      Reporting
  GROUP BY 
      DATEADD(DAY, 0, DATEDIFF(DAY, 0, DateTime))
  ORDER BY 
      DateTime DESC
  
  /** Group by one day method 2 **/
  SELECT 
      SUM(Id) AS Id, 
      MIN(DATEADD(DAY, 0, DATEDIFF(DAY, 0, DateTime))) AS DateTime 
  FROM 
      Reporting
  GROUP BY 
      DATEPART(YEAR, DateTime), 
      DATEPART(MONTH, DateTime), 
      DATEPART(DAY, DateTime)
  ORDER BY 
      DateTime DESC
  </code></pre>
  
  <p>I was hoping that it would be as easy as to increase the number 0 in the queries but that does not seem to work. Is there an easy solution for this because I could not find any examples on the web?</p>
  
  <p>One other requirement would be that the start of the period (and -if easy- the end) should be added as column(s) (type: dateTime).</p>
  
  <p>Can anybody push me in the right direction with this?</p>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT:</p>
  
  <p>The question is probably not very good explained, the answer that is given does help me further. I will post another question with my specific use case if I get stuck again.</p>