while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
$Van = date_create($row{'Van'});
$Tot = date_create($row{'Tot'});
$GAVan = date_create($row{'Van'});
$GATot = date_create($row{'Tot'});
if (date_format($GAVan, 'd') != '01')
{
date_modify($GAVan, '+1 month');
$GAVan = date_create(date_format($GAVan, 'Y/m') . '/01');
}
// Als tot datum de laatste van de maand is ==> OK; anders zet dag op 1 en trek een dag af
$LastOfMonth = date_create(date_format($GATot, 'Y/m') . '/01');
date_modify($LastOfMonth, '+1 month');
date_modify($LastOfMonth, '-1 day');
if ($LastOfMonth != $GATot)
{
$GATot = date_create(date_format($GATot, 'Y/m') . '/01');
date_modify($GATot, '-1 day');
}
print "<tr><td>" . date_format($Van, 'd/m/Y') . "</td>";
print "<td>" . (is_null($Tot) ? " " : date_format($Tot, 'd/m/Y')) . "</td>";
print "<td>" . date_format($GAVan, 'd/m/Y') . "</td><td>" . date_format($GATot, 'd/m/Y') . "</td>";
print "<td align ='right'>" . number_format($row{'Percentage'} * 100, 0, ',', '.') . "%</td>";
$GAInter = date_diff($GAVan, $GATot);
print "<td align ='right'>" . $GAInter->format('%R %y j %m m') . "</td><td> </td><td> </td><td> </td></tr>";
}