title: Whats the best way to get the past 24 hour results in T-SQL?
body: <p>I'm working on creating a chart for my client and they want to get the total customer count over a 24 hour, 3 day, 1 week, 1 month, etc period. I'm honestly not the best with SQL, so generating these queries aren't my forte. </p>
  
  <p>In regards to getting the customers over 24 hours, I've come across two "where" statements that may work, but I'm not sure which is the best.</p>
  
  <p><strong>First version:</strong> </p>
  
  <pre><code>WHERE DATEDIFF(hh,CreatedDate,GETDATE())&gt;24
  </code></pre>
  
  <p><strong>Second Version:</strong> </p>
  
  <pre><code>WHERE CreatedDate &gt;= DATEADD(HH, -24, GETDATE())
  </code></pre>
  
  <p>The first version generates 21 rows and the second generates 17 rows (from the same dataset, of course) so obviously one is more accurate than the other. I'm leaning towards the first, but I would like your opinion... please.</p>
  
  <p>Thanks,
  Andrew</p>