3v4l.org

run code in 500+ PHP versions simultaneously
<?php $date = '10.11.2021 14:00'; $diff = (new DateTime($date))->diff(new DateTime()); $lookup = [ 'y' => 'year', 'm' => 'month', 'd' => 'day', 'h' => 'hour', 'i' => 'minute', ]; $output = 'mere seconds'; foreach ($lookup as $property => $word) { if ($amt = $diff->$property) { if ($property === 'd' && $diff->$property >= 7) { $amt = intdiv($diff->$property, 7); $word = 'week'; } $output = "$amt $word" . ($amt !== 1 ? 's' : ''); break; } } echo "for $output";
Output for 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
for 4 years

preferences:
48.14 ms | 700 KiB | 4 Q