<?php
$dateFim ="";
$date1 = "12/06/2012";
// data americana
$date2 = "12/06/2017";
// data americana
// ano data inicial
// ano data final
$difAno=$year2-$year1;
// se a diferença em anos for maior que 0 calculamos ano inicial e final
if ($difAno>0){
// para ano inicial
$fim = ($year1."-12-31");
$datetime1 = new DateTime($dateInicio);
$datetime2 = new DateTime($fim);
$interval = $datetime1->diff($datetime2);
echo "Ano: ".($year1)." - ";
echo $interval->format('%m Meses %d dias');
echo "\n";
// para ano final
$inicio = ($year2."-01-01");
$datetime1 = new DateTime($inicio);
$datetime2 = new DateTime($dateFim);
$interval = $datetime2->diff($datetime1);
echo "Ano: ".($year2)." - ";
echo $interval->format('%m Meses %d dias');
echo "\n";
}
// se a diferença entre os anos for maior que 1 fazemos um loop para calcular os demais
if ($difAno>1){
for ($x = 1; $x <= $difAno-1; $x++) {
echo "Ano: ".($year1+$x)." - ";
echo date("z", mktime(0,0,0,12,31,($year1+$x))) + 1; echo " = 12 meses \n";
}
}
PD9waHAKCgokZGF0ZUZpbSA9IiI7CgokZGF0ZTEgPSAiMTIvMDYvMjAxMiI7CiRkYXRlMSA9IHN0cl9yZXBsYWNlKCIvIiwgIi0iLCAkZGF0ZTEpOwovLyBkYXRhIGFtZXJpY2FuYQokZGF0ZUluaWNpbyA9IGRhdGUoJ1ktbS1kJywgc3RydG90aW1lKCRkYXRlMSkpOwoKJGRhdGUyID0gIjEyLzA2LzIwMTciOwokZGF0ZTIgPSBzdHJfcmVwbGFjZSgiLyIsICItIiwgJGRhdGUyKTsKLy8gZGF0YSBhbWVyaWNhbmEKJGRhdGVGaW0gPSAgZGF0ZSgnWS1tLWQnLCBzdHJ0b3RpbWUoJGRhdGUyKSk7CiRkYXRlRmltID0gZGF0ZSgnWS1tLWQnLCBzdHJ0b3RpbWUoJGRhdGVGaW0uICcgKyAxIGRheXMnKSk7CgokdGltZTE9c3RydG90aW1lKCRkYXRlMSk7Ci8vIGFubyBkYXRhIGluaWNpYWwKJHllYXIxPWRhdGUoIlki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