<?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";
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Month: 63, Week: 3
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/qY2OX on line 18
Process exited with code 255.