Answers for "how to find number of sundays between two dates in php"

PHP
2

Get the number of days between two dates in PHP

$startDate = new DateTime("2019-10-27");
$endDate = new DateTime("2020-04-11");

$difference = $endDate->diff($startDate);
echo $difference->format("%a");
Posted by: Guest on January-14-2021
0

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

<?php
    $startDate = "01-10-2020"; 
    $endDate = "31-10-2020"; 
    $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); 
    $totaldays = 0;
    foreach ($resultDays as $key => $value)
    {
        if($key == "Monday")
            $totaldays += $value;
        if($key == "Friday")
            $totaldays += $value;     
    }
    echo $totaldays;
?>
  //@sujay
Posted by: Guest on October-22-2020

Code answers related to "how to find number of sundays between two dates in php"

Browse Popular Code Answers by Language