title: Get start and end dates of month in between two dates in SQL?
body: <p>I have the following function which is supposed to return the start and end dates of the months in between two months, the problem how ever is that since this month is 28 days the function is calculating all the upcoming months on a 28 day basis thus returning the following wrong values.</p>
  
  <pre><code>StartDate   EndDate
  -----------------------   
  2013-02-01  2013-02-28 
  2013-03-01  2013-03-28 
  2013-04-01  2013-04-28 
  
  
  
  declare @sDate datetime,
          @eDate datetime;
  
  select  @sDate = '2013-02-25',
          @eDate = '2013-04-25';
  
  ;with months as
  (
    select DATEADD(mm,DATEDIFF(mm,0,@sDate),0) StartDate, 
    DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@sDate)+1,0)) EndDate
  
    union all
    select dateadd(mm, 1, StartDate),
      dateadd(mm, 1, EndDate)
    from months
    where dateadd(mm, 1, StartDate)&lt;=  @eDate
  )
  
  select * from months
  </code></pre>
  
  <p>how can I modify this to return the right dates?</p>