3v4l.org

run code in 300+ PHP versions simultaneously
<?php function time_elapsed_string($datetime, $full = false) { $now = new DateTime; $ago = new DateTime($datetime); $diff = $now->diff($ago); $diff->w = floor($diff->d / 7); $diff->d -= $diff->w * 7; $periods = array( 'y' => ['jaar', 'jaren'], 'm' => ['maand', 'maanden'], 'w' => ['week', 'weken'], 'd' => ['dag', 'dagen'], 'h' => ['uur', 'uren'], 'i' => ['minuut', 'minuten'], 's' => ['seconde', 'seconden'] ); $parts = array(); foreach ($periods as $k => &$v) { if ($diff->$k) { $parts[] = $diff->$k . ' ' . $v[$diff->$k > 1]; } } if (!$full) $parts = array_slice($parts, 0, 1); return $parts ? implode(', ', $parts) . ' ago' : 'just now'; } echo time_elapsed_string('2020-03-21 00:30:16') . PHP_EOL; echo time_elapsed_string('2020-03-21 00:30:16', true) . PHP_EOL;

preferences:
78.94 ms | 406 KiB | 5 Q