title: Total working days between two dates with custom offday
body: <p>I want to calculate total working days between two dates by using custom off day. I inserted Monday,Saturday and Sunday is off days into table. But,when I calculate from start date 2015-07-26 and end date 2015-08-26,the result is correct. However,if start date 2015-08-01 and end date 2015-08-31,the result is incorrect.</p>
  
  <p>How can I do that?</p>
  
  <p>Here is my code</p>
  
  <pre><code>&lt;?php 
  include 'connect.php';
  error_reporting(E_ALL ^ E_NOTICE);
  if (isset($_POST['startdate']) &amp;&amp; isset($_POST['enddate']))
  {
          $startdate=$_POST['startdate'];
          $enddate=$_POST['enddate'];
          $no = 0;
  
      $daysdiff = floor(((strtotime($enddate) -strtotime($startdate)) / 86400)+1); 
          echo "total day is".$daysdiff;
  
      $startdate = new DateTime($startdate);
      $enddate= new DateTime($enddate);
      $interval = DateInterval::createFromDateString('1 day');
      $period = new DatePeriod($startdate, $interval, $enddate);
  
      $res=mysql_query("SELECT * From working_day") or die(mysql_error());
      while ($row = mysql_fetch_assoc($res))
      {
          $id=$row['id'];
          $name_value=$row['off_days'];
  
  
          foreach ($period as $dt)
          {
              if (($dt-&gt;format('N')== $id ))
              {
              $no++;
              //$result=$daysdiff-$no;
              }
          }
          $result=$daysdiff-$no;                      
  
      }
      echo "&lt;input class='form-control' type='text' name='working_day' value='$result'  /&gt;";
  
  }
  ?&gt;
  </code></pre>