echo "<h1>Расчет за период с $dtstart по $dtend</h1>";
$date=$dtstart;
while($date <= $dtend){
echo "$date<br/>";
if (trim($date)==getLastDayOfMonth2(trim($date))) {
echo "<b>$date</b><br/>";
};
$date = date('Y-m-d', strtotime($date.' + 1 days'));
};
function getLastDayOfMonth2($dateInISO8601){
$date = explode('-', $dateInISO8601);
$zx=$date;
if ( !checkdate ( $date[1] , $date[2] , $date[0] ) )
return false;
$start = new DateTime( $dateInISO8601 );
$end = new DateTime( $dateInISO8601 );
$end->add( new DateInterval( 'P2M' ) );
$interval = new DateInterval( 'P1D' );
$daterange = new DatePeriod($start, $interval, $end);
$prev = $start;
foreach ($daterange as $date){
if ($prev->format('m') != $date->format('m') )
return $zx[0]."-".$zx[1]."-".(int) $prev->format('d');
$prev = $date;
}
return false;
}