3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Input data $startTimestamp = '2023-08-05 14:45:05'; $endTimestamp = '2023-08-09 13:00:14'; // The interval expressed using `DateTime` objects $begin = new DateTimeImmutable($startTimestamp); $end = new DateTimeImmutable($endTimestamp); // The beginning of the first day (midnight) $start = $begin->setTime(0, 0, 0); // What its name says $oneDay = new DateInterval('P1D'); $output = []; // Check each day of the interval [$start, $end) $period = new DatePeriod($start, $oneDay, $end); foreach ($period as $day) { $s = max($day, $begin); // day start (midnight, except for the first day) $e = min($end, $day->add($oneDay)); // day end (midnight, except for the last day) $l = $e->diff($s); // day length // Express the day length in minutes $output[$day->format('Y-m-d')] = 24 * 60 * $l->d + 60 * $l->h + $l->i + round($l->s / 60); } print_r($output);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
Array ( [2023-08-05] => 555 [2023-08-06] => 1440 [2023-08-07] => 1440 [2023-08-08] => 1440 [2023-08-09] => 780 )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
115.32 ms | 407 KiB | 5 Q