title: SQL Query: Where datetime = past 24 hours, how?
body: <pre><code>select eventdatetime, eventid, sCode, sNarrative
  FROM [Blue Prism].dbo.BPAAuditEvents;    
  </code></pre>
  
  <p>eventdatetime type is datetime.</p>
  
  <p>I need to create a query to return these columns, where eventdatetime = the last 24 hours.</p>
  
  <p>How can I do this?</p>
  
  <p>I've tried a bunch of queries but I'm not having any luck.</p>
  
  <p>1) <code>WHERE DATE(eventdatetime) = DATE(NOW())</code> </p>
  
  <p>This returned a syntax error</p>
  
  <blockquote>
    <p>SQL Error [195] [S00010]: 'DATE' is not a recognized built-in function name.</p>
  </blockquote>
  
  <p>2) <code>where convert(varchar(10), eventdatetime, 102) 
      = convert(varchar(10), getdate(), 102)</code></p>
  
  <p>This returned no data, but also no errors.</p>
  
  <p>3) <code>WHERE CAST(eventdatetime AS DATE) = CAST(GETDATE() AS DATE)</code></p>
  
  <p>This also returned no data, but also no errors.</p>
  
  <pre><code>select eventdatetime, eventid, sCode, sNarrative
  FROM [Blue Prism].dbo.BPAAuditEvents;
  </code></pre>
  
  <p>I expect the output to be records where eventdatetime &lt;= 24 hours from when the query was ran.</p>