Created
March 26, 2010 21:47
-
-
Save anselmobattisti/345439 to your computer and use it in GitHub Desktop.
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
/** | |
* somar_dias_uteis | |
* | |
* @abstract Soma dias úteis a uma data | |
* | |
* @param unknown_type $str_data data original | |
* @param unknown_type $int_qtd_dias_somar dias que serão somados | |
* @param unknown_type $formato formato da saida | |
* | |
* @return string | |
* | |
* @author Original http://leandrovieira.com/archive/somando-dias-uteis-a-uma-data-especifica-com-php | |
*/ | |
public static function somar_dias_uteis($str_data,$int_qtd_dias_somar = 7, $formato = "d/m/Y") { | |
$str_data = substr($str_data,0,10); | |
if ( preg_match("@/@",$str_data) == 1 ) { | |
$str_data = implode("-", array_reverse(explode("/",$str_data))); | |
} | |
$array_data = explode('-', $str_data); | |
$count_days = 0; | |
$int_qtd_dias_uteis = 0; | |
while ( $int_qtd_dias_uteis < $int_qtd_dias_somar ) { | |
$count_days++; | |
if ( ( $dias_da_semana = gmdate('w', strtotime('+'.$count_days.' day', mktime(0, 0, 0, $array_data[1], $array_data[2], $array_data[0]))) ) != '0' && $dias_da_semana != '6' ) { | |
$int_qtd_dias_uteis++; | |
} | |
} | |
return gmdate($formato,strtotime('+'.$count_days.' day',strtotime($str_data))); | |
}.php |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment