title: Calculate recurring interval from start date
body: <p>This is what I have:  </p>
  
  <pre><code>Start Date (yyyy-mm-dd)  
  Interval : n   
  Interval Type : hour, day, week, month, year 
  </code></pre>
  
  <p>This is what I need:
  is the current time/date in the recurring interval  </p>
  
  <pre><code>Data/Example:  
  Today : 2013-07-16 12:37  
  
  Event Data :  
  Start Date : 2012-04-03 12:30  
  Interval : 2  
  Interval Type : week  
  </code></pre>
  
  <p>2012-04-03 is a Tuesday. So is 2013-07-16. How to calculate (in PHP) if the recurrence of every second tuesday will hit todays date or be last tuesday?</p>
  
  <p>Any one?</p>
  
  <p>Edit:<br>
  @hek2mgl  I made it work this way  </p>
  
  <pre><code>/* Check for recurring window is legit */
  $interval_string ="P".$mm["mm_reoc_interval"];
  switch ($mm["mm_reoc_interval_type"])
  {
      case 1: $interval_string .= "H"; break;
      case 2: $interval_string .= "D"; break;
      case 3: $interval_string .= "W"; break;
      case 4: $interval_string .= "M"; break;
      case 5: $interval_string .= "Y"; break;
  }
  
  $start = DateTime::createFromFormat("Y-m-d H:i:s", $mm["mm_reoc_start_date"]." ".$mm["mm_reoc_start_hour"].":00");
  $end = DateTime::createFromFormat("Y-m-d H:i:s", $date_time);
  $interval = new DateInterval($interval_string);
  $occurrences = 3;
  $period = new DatePeriod($start,$interval,$end);
  foreach($period as $dt){
    $date_array[] = $dt-&gt;format("Y-m-d");
  }
  
  if(in_array($today, $date_array)) 
  {
         bla.bla..
      }
  </code></pre>