This questions will seems similar to old ones about month but I have a special issue. I am not trying to count the months between two dates, but I am trying to get the months included in two dates. I explain. I have 2 dates :
$begin = new DateTime( '2014-07-20' );
$end = new DateTime( '2014-10-10' );
Between those two dates, I have 4 months included : July, August, September, October. But with the script I am using, I am not able to find 4 months included but only 3. This is the script :
$interval = DateInterval::createFromDateString('1 month');
$period = new DatePeriod($begin, $interval, $end);
$counter = 1;
foreach($period as $dt) {
echo $dt->format( 'm' );
$counter++;
}
echo $counter;
How to count all those 4 months in a loop ?