3v4l.org

run code in 300+ PHP versions simultaneously
<?php function weekCounter($startDate,$endDate){ //calculate # of full weeks between dates $secsPerWeek = 60 * 60 * 24 * 7; $fullWeeks = floor((strtotime($endDate) - strtotime($startDate))/$secsPerWeek); $fullMonths = floor($fullWeeks/4); $weeksRemainder = $fullWeeks % 4; // weeks that don't fit in a month return "Months: $fullMonths, Weeks: $weeksRemainder"; } $startDate = '2016-06-13'; $endDates = ['2016-06-20','2016-06-27','2016-07-04']; foreach($endDates as $endDate) echo weekCounter($startDate,$endDate)."\n";

preferences:
57.55 ms | 402 KiB | 5 Q