Hello, who helps me get months within a range of example dates
$fechaRegistro="2017-07-21";
$fechaCorte="2017-11-21";
I want to get the months from $fechaRegistro
to $fechaCorte
I have programmed the following:
Function contarMeses($a){
$f1 = new DateTime( $a[0]);
$f2 = new DateTime($a[1]);
$d = $f1->diff($f2);
$m = ($d->y * 12)+$d->m;
Return $m;
}
function calculaFecha($a) {
$modo = ($a[0] == "months")? "months" : $a[0];
$valor = $a[1];
$fecha_inicio = strtotime($a[2]);
$calculo = strtotime("$valor $modo","$fecha-inicio");
Return date("Y-m-d",$calculo);
}
function verMeses($a){
$f1 = $a[0];
$f2 = $a[1];
$countMeses = contarMeses(array($f1,$f2));
$m = "";
For($i = 0; $i < $countMeses ; $i++){
$m .= calculaFecha( array("" , $i+1 , $f1)."<br>";
}
Echo $m;
}
verMeses(
array(
"2017-07-21",
"2017-11-21"
)
);