title: Last n-th day before today
body: <p>Given just an integer between 1 and 31, how can I get "last n-th day date" (meaning last is in the past)? I'm looking for an equivalent of <code>strtotime("last Monday")</code> but for day of month - something like <code>strtotime("last 26th")</code>.</p>
  
  <p>For example if we assume that today is 2018-06-04:  </p>
  
  <ul>
  <li>If my number is 3 then 2018-06-03 should be returned</li>
  <li>If my number is 4 then 2018-06-04 should be returned</li>
  <li>If my number is 5 then 2018-05-05(5th day of last month) should be returned</li>
  </ul>
  
  <p>Here is what I've tried so far:</p>
  
  <pre><code>if(intval(date("d"))&gt;=$day)
  echo date("Y-m-d",strtotime("first day of this month +$day days"));
  else
  echo date("Y-m-d",strtotime("first day of last month +$day days"));
  </code></pre>