<?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'));
$result = getYearsBetween($start, $end);
var_export($result);
- Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.9, 8.1.14 - 8.1.28, 8.2.1 - 8.2.18, 8.3.0 - 8.3.6
- 21
- Output for 8.1.10 - 8.1.13, 8.2.0
- -22
- Output for 7.4.0 - 7.4.33
- Parse error: syntax error, unexpected ')', expecting variable (T_VARIABLE) in /in/nmPAj on line 6
Process exited with code 255.
preferences:
113.75 ms | 401 KiB | 121 Q