title: Prior Month for Prior Year
body: <p>I have been able to Declare and Set grabbing the prior months data.  </p>
  
  <pre><code>DECLARE @FirstDayofPrevMonth datetime
  SET @FirstDayofPrevMonth = DATEADD(mm, DATEDIFF(m,0,GETDATE())-1,0)
  DECLARE @LastDayofPrevMonth datetime  
  SET @LastDayofPrevMonth = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))
  </code></pre>
  
  <p>What I now need is to be able to set and declare prior month, prior year....</p>
  
  <p>to be clear, this does work for me. I get the expected result which is Aug 2014.  What I'm looking to do, is get Aug 2013 and so on.</p>
  
  <p>UPDATE:
  I thought I would share two other pieces I added to my code that may be helpful to others.</p>
  
  <p>I used the below answer and added to it</p>
  
  <pre><code>DECLARE @FirstDayofPrevMonth datetime
  SET @FirstDayofPrevMonth = DATEADD(mm, DATEDIFF(m,0,GETDATE())-1,0)
  DECLARE @LastDayofPrevMonth datetime
  SET @LastDayofPrevMonth = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))  
  </code></pre>
  
  <p>-- to be used for the prior year completed month</p>
  
  <pre><code>DECLARE @FirstDayofPrevMonthLY datetime
  SET @FirstDayofPrevMonthLY = DATEADD(year,-1,@FirstDayofPrevMonth)
  DECLARE @LastDayofPrevMonthLY datetime
  SET @LastDayofPrevMonthLY = DATEADD(year,-1,@LastDayofPrevMonth)
  </code></pre>
  
  <p>--This is to be used if you want for dates in the current Quarter</p>
  
  <pre><code>DECLARE @FirstDayofCQ datetime
  SET @FirstDayofCQ = DATEADD(qq, DATEDIFF(qq, 0, GETDATE()), 0)
  DECLARE @LastDayofCQ datetime
  SET @LastDayofCQ =DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) + 1, 0)
  </code></pre>
  
  <p>--This is to be used for the Prior Quarter</p>
  
  <pre><code>DECLARE @FirstDayofPrevQ datetime
  SET @FirstDayofPrevQ = DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) - 1, 0)
  DECLARE @LastDayofPrevQ datetime
  SET @LastDayofPrevQ = DATEADD(dd, -1, DATEADD(qq, DATEDIFF(qq, 0, GETDATE()), 0))
  </code></pre>