So i found this code from the link bellow and it worked fine like 2 days ago but then just stops working. when i gave it the time from mysql CURRENT TIMESTAMP it just outputs 8, 7 or 6 hours no matter how long it has been. if anyone knows how to improve this or a better way to do the function please submit it here or give me a link to it. I have tried it on php 5.6 and php 7 but neither fix it.
example:
$time = 2017-09-11 17:10:51
input:
time_elapsed_string($time);
output:
5 hours ago
#function from https://stackoverflow.com/questions/1416697/converting-timestamp-to-time-ago-in-php-e-g-1-day-ago-2-days-ago
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;
    $string = array(
        'y' => 'year',
        'm' => 'month',
        'w' => 'week',
        'd' => 'day',
        'h' => 'hour',
        'i' => 'minute',
        's' => 'second',
    );
    foreach ($string as $k => &$v) {
        if ($diff->$k) {
            $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
        } else {
            unset($string[$k]);
        }
    }
    if (!$full) $string = array_slice($string, 0, 1);
    return $string ? implode(', ', $string) . ' ago' : 'just now';
}
 
    