Number Of Week Days Between Two Dates using PHP
Dec 30, 2021 . Admin

Hello Dev,
Now let's see example of how to use number of week days between two dates example. We will check how to use number of week days between two dates. This is a short guide on use number of week days between two dates in php. Let's get started with how to use number of week days between two dates in php.
Here i will give you many example how to use number of week days between two dates using php.
Example:<?php // input start and end date $startDate = "01-01-2018"; $endDate = "01-01-2019"; $resultDays = array('Monday' => 0, 'Tuesday' => 0, 'Wednesday' => 0, 'Thursday' => 0, 'Friday' => 0, 'Saturday' => 0, 'Sunday' => 0); // change string to date time object $startDate = new DateTime($startDate); $endDate = new DateTime($endDate); // iterate over start to end date while($startDate <= $endDate ){ // find the timestamp value of start date $timestamp = strtotime($startDate->format('d-m-Y')); // find out the day for timestamp and increase particular day $weekDay = date('l', $timestamp); $resultDays[$weekDay] = $resultDays[$weekDay] + 1; // increase startDate by 1 $startDate->modify('+1 day'); } // print the result print_r($resultDays); ?>Output:
Array ( [Monday] => 53 [Tuesday] => 53 [Wednesday] => 52 [Thursday] => 52 [Friday] => 52 [Saturday] => 52 [Sunday] => 52 )
It will help you...