how to find two date under how many mondays find in php

Solutions on MaxInterview for how to find two date under how many mondays find in php by the best coders in the world

showing results for - "how to find two date under how many mondays find in php"
Rébecca
26 Feb 2018
1<?php
2    $startDate = "01-10-2020"; 
3    $endDate = "31-10-2020"; 
4    $resultDays = array('Monday' => 0, 
5    'Tuesday' => 0, 
6    'Wednesday' => 0, 
7    'Thursday' => 0, 
8    'Friday' => 0, 
9    'Saturday' => 0, 
10    'Sunday' => 0); 
11  
12    // change string to date time object 
13    $startDate = new DateTime($startDate); 
14    $endDate = new DateTime($endDate); 
15  
16    // iterate over start to end date 
17    while($startDate <= $endDate ){ 
18        // find the timestamp value of start date 
19        $timestamp = strtotime($startDate->format('d-m-Y')); 
20        // find out the day for timestamp and increase particular day 
21        $weekDay = date('l', $timestamp); 
22        $resultDays[$weekDay] = $resultDays[$weekDay] + 1; 
23        // increase startDate by 1 
24        $startDate->modify('+1 day'); 
25    } 
26    // print the result 
27    print_r($resultDays); 
28    $totaldays = 0;
29    foreach ($resultDays as $key => $value)
30    {
31        if($key == "Monday")
32            $totaldays += $value;
33        if($key == "Friday")
34            $totaldays += $value;     
35    }
36    echo $totaldays;
37?>
38  //@sujay