3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getYearsBetween( \DateTimeImmutable $startDate, \DateTimeImmutable $endDate, ): int { $dateInterval = $startDate->diff($endDate, true); return $dateInterval->y; } $start = new \DateTimeImmutable('2000-11-01 09:29:22.907606', new \DateTimeZone('America/Chicago')); $end = new \DateTimeImmutable('2022-06-06 11:00:00.000000', new \DateTimeZone('America/New_York')); $end = $end->setTimezone(new \DateTimeZone('America/Chicago')); $result = getYearsBetween($start, $end); var_export($result);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
21
Output for 7.4.0 - 7.4.33
Parse error: syntax error, unexpected ')', expecting variable (T_VARIABLE) in /in/RK34h on line 6
Process exited with code 255.

preferences:
120.16 ms | 401 KiB | 121 Q