While, limit the result

0

I would like to limit the while result. My code displays the number of days between two dates correctly, but I would like the result (in the while) to show the dates every 30 days, as each line would be a month, to make it easier to count.

Ex:

  

01-01-2017, 02-01-2017, ... completed 30 days enter
  01-01-2017, 02-01-2017, ... completed 30 days enter
  01-01-2017, 02-01-2017, ... completed 30 days enter

Follow my code

<?php
include "exibe_ico.php";
if (empty($_POST['data_inicial']) or empty($_POST['data_final']) ) { echo "<script> window.alert('Preencha a data!'); history.back(); </script>"; exit(); }

ValidaData($_POST['data_inicial']);
ValidaData($_POST['data_final']);

$data_inicial = $_POST['data_inicial'];
$data_final = $_POST['data_final'];

function geraTimestamp($data) {
$partes = explode('/', $data);
return mktime(0, 0, 0, $partes[1], $partes[0], $partes[2]);
}

$time_inicial = geraTimestamp($data_inicial);
$time_final = geraTimestamp($data_final);

$diferenca = $time_final - $time_inicial; // 19522800 segundos
$dias = ((int)floor( $diferenca / (60 * 60 * 24))+1); // 225 dias

echo "<table border='1' width=80%>";
echo "<tr>";
echo "<th>Início</th>";
echo "<th>Fim</th>";
echo "<th>Nº dias</th>";
echo "</tr>";


echo "<tr>";
echo "<td align='center'>$data_inicial</td>";
echo "<td align='center'>$data_final</td>";
echo "<td align='center'>$dias</td>";
echo "</tr>";

echo "</table>";

echo "<p><div align=left><a href='dias.php?acao=entrar'><< Voltar</a></font></div>";

?>

<?php
$Dias = 0;
$contagem = 1;
$enter = 1;
$result = date("d-m-Y", strtotime(str_replace('/', '-', $data_inicial)));
while($Dias < $dias)
{
echo "
<table>
<tr>
<td width=60 align='center'>{$contagem}º dia</td>
<td width=100 align='center'>"; echo date("d-m-Y", strtotime("+ $Dias days",strtotime($result))); echo "</td>
</tr>
</table>
";
$Dias++;
$contagem++;

}
    
asked by anonymous 04.09.2017 / 16:28

1 answer

1

Try to get the month of the timestamp

$php_date = getdate($timestamp);
$mes = date("m", $timestamp); 

So in every change of the month you create the line break.

    
04.09.2017 / 16:49