Elapsed time is simply the amount of time that passes from the beginning of an event to its end. In this lesson, you will learn how to solve for elapsed time and explore how it can be used in your everyday life.
In this post we will show how to get elapsed time in php. We will use a function where you just need to pass the time string which you want to compare from the current timestamp.
See the code below
function get_time_elapsed($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)
$v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
if (!$full) $string = array_slice($string, 0, 1);
return $string ? implode(', ', $string) . ' ago' : 'just now';
echo get_time_elapsed("2017-02-28 02:46:55");
Pass your date time string which you need to compare and you will get the result you are looking for.