title: How to calculate working hours between two dates excluding holidays and weekends?
body: <p>Let's say that I have two dates:</p>
  
  <pre><code>$initialDate = '08/10/2015 09:30:24 am';
  $finalDate = '15/10/2015 15:47:38 pm';
  $holiday = '12/10/2015';
  </code></pre>
  
  <p><strong>I have to consider the hour of these days.</strong></p>
  
  <pre><code>Hours to consider : 8 hours per day;
  Start : 8 pm
  End: 18 pm (24 hours format )
  Lunch break start: 12:00 pm
  Lunch break end: 14:00 pm
  
  Example 1 : From 08/10/2015 10:00:00 to 09/10/2015 17:00:00 results 13 working hours. ( excludes lunch break )
  Example 2 : From 08/10/2015 14:00:00 to 09/10/2015 18:00:00 results 12 working hours. ( Do not exclude 2 hours from begin date, because starts after 14:00 pm, lunch break )
  Example 3 : From 08/10/2015 16:00:00 to 09/10/2015 18:00:00 results 10 working hours. ( Do not exclude 2 hours from begin date, because starts after 14:00 pmm lunch break )
  Exampld 4 : From 08/10/2015 08:00:00 to 09/10/2015 11:00:00 results 14 working hours. ( Exclude 2 hours from begin date, and do not exclude 2 hours from end date, because isn't after 14:00 pm  )
  </code></pre>
  
  <p>And I have to calculate the working hours and working days between those two dates, excluding weekends and Holidays, how can I do that ? I'm using PHP.</p>
  
  <p>PS: I Already have something, but without lunch break... I made a research here on StackOverFlow.</p>
  
  <p>Code:
      
  
  <pre><code>function get_workdays($dataInicial,$dataFinal){
  // arrays
  $days_array = array();
  $skipdays = array("Saturday", "Sunday");
  $skipdates = get_feriados();
  
  // other variables
  $i = 0;
  $current = $dataInicial;
  
  if($current == $dataFinal) // same dates
  {
      $timestamp = strtotime($dataInicial);
      if (!in_array(date("l", $timestamp), $skipdays)&amp;&amp;!in_array(date("Y-m-d", $timestamp), $skipdates)) {
          $days_array[] = date("Y-m-d",$timestamp);
      }
  }
  elseif($current &lt; $dataFinal) // different dates
  {
      while ($current &lt; $dataFinal) {
          $timestamp = strtotime($dataInicial." +".$i." day");
          if (!in_array(date("l", $timestamp), $skipdays)&amp;&amp;!in_array(date("Y-m-d", $timestamp), $skipdates)) {
              $days_array[] = date("Y-m-d",$timestamp);
          }
          $current = date("Y-m-d",$timestamp);
          $i++;
      }
  }
  return $days_array;
  
   }
  
  function get_feriados(){
  $dateAno = Date('Y');
  $days_array = array(
          $dateAno.'-10-12', // Padroeira do Brasil/ Dias das Crianças
          $dateAno.'-11-02',  // Finados
          $dateAno.'-12-25'  // Finados
  );
  return $days_array;
  
   }
  
  date_default_timezone_set('America/Sao_Paulo');
  $dateAno = Date('Y');
  $dataInicial = Date('08/10/2015 H:i');
  $dataFinal = Date('13/10/2015 H:i');
  
  // timestamps
  $from_timestamp = strtotime(str_replace('/', '-', $dataInicial));
  $to_timestamp = strtotime(str_replace('/', '-', $dataFinal));
  
  // work day seconds
  $workday_start_hour = 9;
  $workday_end_hour = 17;
  $workday_seconds = ($workday_end_hour - $workday_start_hour)*3600;
  
  // work days beetwen dates, minus 1 day
  $from_date = date('Y-m-d',$from_timestamp);
  $to_date = date('Y-m-d',$to_timestamp);
  
  $workdays_number = count(get_workdays($from_date,$to_date))-1;
  $workdays_number = $workdays_number&lt;0 ? 0 : $workdays_number;
  
  // start and end time
  $start_time_in_seconds = date("H",$from_timestamp)*3600+date("i",$from_timestamp)*60;
  $end_time_in_seconds = date("H",$to_timestamp)*3600+date("i",$to_timestamp)*60;
  
  // final calculations
  $working_hours = ($workdays_number * $workday_seconds + $end_time_in_seconds - $start_time_in_seconds) / 86400 * 24;
  
  print_r('&lt;br/&gt; Horas úteis '.$working_hours);
  
  
  }
  </code></pre>
  
  <p>But don't consider two hours of break lunch. Can somebody please help me ?</p>