Missing Days only

 <?php

$dateRanges = array(

    array('from' => '2024-04-01 03:00 PM', 'to' => '2024-04-05 03:00 PM'),

    array('from' => '2024-04-10 03:00 PM', 'to' => '2024-04-15 03:00 PM'),

    array('from' => '2024-04-20 03:00 PM', 'to' => '2024-04-22 03:00 PM'),

    // Add more date ranges as needed

);


function calculateMissingDays($dateRanges) {

    $missingDays = array();


    foreach ($dateRanges as $index => $range) {

        $from = new DateTime($range['from']);

        $to = new DateTime($range['to']);

        

        if ($index > 0) {

            $prevTo = new DateTime($dateRanges[$index - 1]['to']);

            $diff = $prevTo->diff($from)->days;

            for ($i = 1; $i < $diff; $i++) {

                $missingDays[] = $prevTo->modify('+1 day')->format('Y-m-d h:i A');

            }

        }

    }

    

    return $missingDays;

}


$missingDays = calculateMissingDays($dateRanges);

print_r($missingDays);

?>

Comments

Popular posts from this blog

How to seperate character from string in php

How to Delete record using PHP Ajax

Uploads Only 10 files in month step by step