title: Counting working hours (different for weekdays and Saturdays)
body: <p>I tried <a href="https://stackoverflow.com/questions/8914360/calculating-working-hours-between-two-dates">@ebelendez</a>'s code for <em>Calculating working hours between two dates</em>, however I'm confused on how to set the value of Saturdays by 3 hours (08:00-11:00). For example, the working hours per day during weekdays is 8 hours (excluding 1 hour break), let's say I want to get the total working hours from Thursday to Saturday, the expected result would be 19 hours.</p>
  <p>Here is what I've done. Can someone help me with this?</p>
  <pre><code>$from = '2022-04-21 07:00:00';
  $to = '2022-04-23 16:00:00';
  
  echo abs(get_working_hours($from, $to));
  
  function get_working_hours($from,$to){
      //config
      $ini_time = [7,0]; //hr, min
      $end_time = [16,0]; //hr, min
      //date objects
      $ini = date_create($from);
      $ini_wk = date_time_set(date_create($from),$ini_time[0],$ini_time[1]);
      $end = date_create($to);
      $end_wk = date_time_set(date_create($to),$end_time[0],$end_time[1]);
      //days
      $workdays_arr = get_workdays($ini,$end);
      $workdays_count = count($workdays_arr);
      $workday_seconds = (($end_time[0] * 60 + $end_time[1]) - ($ini_time[0] * 60 + $ini_time[1])) * 60 - 3600;
      //get time difference
      $ini_seconds = 0;
      $end_seconds = 0;
      if(in_array($ini-&gt;format('Y-m-d'),$workdays_arr)) $ini_seconds = $ini-&gt;format('U') - $ini_wk-&gt;format('U');
      if(in_array($end-&gt;format('Y-m-d'),$workdays_arr)) $end_seconds = $end_wk-&gt;format('U') - $end-&gt;format('U');
      $seconds_dif = $ini_seconds &gt; 0 ? $ini_seconds : 0;
      if($end_seconds &gt; 0) $seconds_dif += $end_seconds;
      //final calculations
      $working_seconds = ($workdays_count * $workday_seconds) - $seconds_dif;
      return $working_seconds / 3600; //return hrs
  }
  
  function get_workdays($ini,$end){
      //config
      $skipdays = [0]; //sunday:0
      $skipdates = []; 
      //vars
      $current = clone $ini;
      $current_disp = $current-&gt;format('Y-m-d');
      $end_disp = $end-&gt;format('Y-m-d');
      $days_arr = [];
      //days range
      while($current_disp &lt;= $end_disp){
          if(!in_array($current-&gt;format('w'),$skipdays) &amp;&amp; !in_array($current_disp,$skipdates)){
              $days_arr[] = $current_disp;
          }
          $current-&gt;add(new DateInterval('P1D')); //adds one day
          $current_disp = $current-&gt;format('Y-m-d');
      }
      return $days_arr;
  }
  </code></pre>