Skip to content

Instantly share code, notes, and snippets.

@mishudark
Last active December 16, 2015 06:29
Show Gist options
  • Save mishudark/5392358 to your computer and use it in GitHub Desktop.
Save mishudark/5392358 to your computer and use it in GitHub Desktop.
<?php
function laboral_days($start, $end, $nowork = array('sun', 'sat'), $festives = array()){
$days = array('sat' => 5, 'sun' => 6);
$time_start = strtotime($start);
$time_end = strtotime($end);
$day_init = date('w', $time_start);
$day_end = date('w', $time_end);
$total_days = ($time_end - $time_start) / (60 * 60 * 24) + 1;
$weeks = floor($total_days / 7);
$efective_days = $total_days - $weeks * count($nowork);
if(($day_end - $day_init) != 0){
foreach($nowork as $d){
$d = $days[$d];
if($d > $day_init && $d <= $day_end){
$efective_days--;
}
}
}
foreach($festives as $d){
$e_t = strtotime($d);
if($e_t >= $time_start && $e_t <= $time_end){
$efective_days--;
}
}
return $efective_days;
}
echo laboral_days('17-04-2013', '30-04-2013');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment