3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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";
based on Z9tlm
Output for 5.6.0 - 7.3.0rc4
Months: 0, Weeks: 1 Months: 0, Weeks: 2 Months: 0, Weeks: 3