Created
September 30, 2016 18:15
-
-
Save davidalves1/e375a7194d004c0346dc89c33754b80c to your computer and use it in GitHub Desktop.
Idéia para criar biblioteca que calcula quantidade de dias úteis entre duas datas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Calcula a quantidade de dias úteis entre duas datas | |
$util = 0; | |
$inicio = date('2016-05-13'); | |
$fim = date('2016-05-27'); | |
function montaFeriados($feriados) { | |
$resposta = []; | |
foreach ($feriados as $feriado) { | |
$resposta[] = date('Y-' . $feriado); | |
} | |
return $resposta; | |
} | |
$feriados = ['12-25', '01-01', '05-01']; | |
for ($i = strtotime($inicio); $i < strtotime($fim); $i = strtotime('+1 day', $i)) { | |
$d = intval(date('N', $i)); | |
if ($d != 6 && $d != 7 && !in_array(date('Y-m-d', $i), montaFeriados($feriados))){ | |
$util += 1; | |
} | |
} | |
echo 'Do dia ' . date('d/m/Y', strtotime($inicio)) . ' ao dia ' . | |
date('d/m/Y', strtotime($fim)) . ' existem ' . $util . ' dias úteis.<br><br>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment