Calculate Number of Working Days Between Two Days in PHP
I am sharing my PHP code to get difference between two dates.
$workingDays = 0;
$startTimestamp = strtotime('2021-06-03');$endTimestamp = strtotime('2022-07-09');for ($i = $startTimestamp; $i <= $endTimestamp; $i = $i + (60 * 60 * 24)) {if (date("N", $i) <= 5) $workingDays = $workingDays + 1;}echo "no. of days: " . $workingDays;
Save code in nofdays.php.
Run program in terminal. Output will be:
$ php nofdays.phpno. of days: 287