title: php datetime class and for loop problem
body: <p>I was wondering if somebody could help with this problem I have.</p>
  
  <p>I have an array which contains the weekdays in which people want to be contacted. I have then created a for loop which adds 1 day to the current date until the day of the week matches a day in which a person wants to be contacted.</p>
  
  <p>The problem I am having is that the loop always goes one day too far. I am just wondering if this is the best way to accomplish what I am trying to do or is there a better way?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>$ScheduleWindow = array('Monday', 'Tuesday');
  
  $date = new DateTime('today');
  
  $dow = getdate($date-&gt;getTimestamp());
  
  for($date, $dow;!in_array($dow['weekday'], $ScheduleWindow);$date-&gt;add(new DateInterval('P1D'))){
  $dow = getdate($date-&gt;getTimestamp());
  }
  
  echo "Next date to contact is" . $date-&gt;format('Y-m-d H:i:s') . "\n";
  </code></pre>
  
  <p>The code currently echoes "Next date in schedule window is2011-01-25 00:00:00" however I need it to be the date 2011-01-24.</p>
  
  <p>Thanks for looking.</p>