title: Select every date where date is equal to today's date minus 1 day - Not working with dateadd on Month/year - T SQL
body: <p>Like the title says, I am trying to build a query that selects all records from a database table where the date is equal to yesterdays date. </p>
  
  <p>The date column in the table is however of the format <code>datetime</code> (with hours, minutes, seconds as well) so I do the select based on the dates year, month and day (times don't matter as long as the date is yesterday).</p>
  
  <p>To achieve this I have build the following query:</p>
  
  <pre><code>SELECT 
      * 
  FROM
      qryTouchBoekingen 
  WHERE 
      (DATEPART(yyyy, myDateTime) = DATEADD(dd, -1, Datepart(dd, GetDate())) 
      AND (DATEPART(mm, myDateTime) = DATEADD(dd, -1, Datepart(mm, GetDate())) 
      AND (DATEPART(dd, myDateTime) = DATEADD(dd, -1, Datepart(dd, GetDate())) )
  ORDER BY
      Starttijd ASC
  </code></pre>
  
  <p>Though this doesn't return any records. When I only use it on the day part of the <code>myDateTime</code> column then it works (but obviously also returns all other years and months with that specific date).</p>
  
  <p>I also couldn't do it using:</p>
  
  <pre><code>SELECT 
      *
  FROM
      qryTouchBoekingen 
  WHERE 
      myDateTime = DATEADD(dd, -1, GetDate())
  </code></pre>
  
  <p>because this give errors on the <code>time</code>. </p>