3v4l.org

run code in 300+ PHP versions simultaneously
<?php function weekCounter($startDate,$endDate=null){ //use today as endDate if no date was supplied $endDate = $endDate? : date('Y-m-d'); //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 //increment from 0-base to 1-base, so first week is Week 1. Same with months $fullMonths++; $weeksRemainder++; return [$fullMonths,$weeksRemainder]; } $startDate = '2016-06-27'; //put function results in $months and $weeks variables list($months,$weeks) = weekCounter($startDate); //you can use the variables however you want echo "Month: $months, Week: $weeks";

preferences:
60.72 ms | 402 KiB | 5 Q