title: SQL syntax for Same Date Last Year
body: <p>I am using SQL Server 2014 and I have the following T-SQL query which pulls data from a View Table:</p>
  
  <pre><code>SELECT * from MyView
  
  WHERE StayDate &gt;= '2014-07-01'
  </code></pre>
  
  <p>I need to add a filter to this query that will be applied on a field called "CreatedOn" (it is datetime field). The filter needs to filter the "CreatedOn" based on the SAME DATE LAST YEAR.</p>
  
  <p>Thus, if today's date is '2015-10-26', my query should look this:</p>
  
  <pre><code>SELECT * from MyView
  
  WHERE StayDate &gt;= '2014-07-01'
  
  AND CreatedOn &lt;= '2014-10-26'
  </code></pre>
  
  <p>Since this query will be used in a PowerPivot environment, I am thinking along these lines:</p>
  
  <pre><code>SELECT * from MyView
  
  WHERE StayDate &gt;= '2014-07-01'
  
  AND CreatedOn &lt;= getdate()
  </code></pre>
  
  <p>How do I modify the getdate() part so that it becomes the Same Date Last Year?</p>