title: MySQL Selecting Dynamic Date Range
body: <p>I have a <code>datetime</code> column and I want to select all rows from the previous 2 complete months (Sept and Oct, currently). Manually I could compose this query as:</p>
  
  <pre><code>where date_column between '2018-09-01' and '2018-10-31'
  </code></pre>
  
  <p>but how can I do this programmatically so the end date is always correct? I was thinking</p>
  
  <pre><code>where date_column between concat(substr(now() - INTERVAL 2 month, 1, 7), '-01') and concat(substr(now() - INTERVAL 1 month, 1, 7), '-31')
  </code></pre>
  
  <p>but the <code>31</code> will be incorrect for November, February, etc.</p>