title: Get the First or Last Friday in a Month
body: <p>I'm trying to write a calendar function like this</p>
  
  <pre><code>function get_date($month, $year, $week, $day, $direction)
  {
      ....
  }
  </code></pre>
  
  <p><code>$week</code> is a an integer (1, 2, 3...), $day is a day (Sun, Mon, ...) or number, whichever is easier. The direction is a little confusing, because it does a different calculation.</p>
  
  <p>For an example, let's call </p>
  
  <p><code>get_date(5, 2009, 1, 'Sun', 'forward');</code></p>
  
  <p>It uses the default, and gets the first Sunday in May ie 2009-05-03. If we call </p>
  
  <p><code>get_date(5, 2009, 2, 'Sun', 'backward');</code></p>
  
  <p>, it returns the second last Sunday in May ie 2009-05-24.</p>