Showing posts with label PHP Calculate Working Days. Show all posts
Showing posts with label PHP Calculate Working Days. Show all posts

Sunday 6 June 2021

Calculate Number of Days PHP

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.php

no. of days: 287




Create .ICS file using PHP code

Recently worked on creating a .ics file in PHP after a very long time, code so thought to share with everybody. Please find below the comple...