We will create a function for this and print the time with function name and it will convert the current timestamp and actual post_submitted timestamp difference.


<?php

function timeAgo($time_ago) {
$time_ago = strtotime($time_ago);
$cur_time   = time();
$time_elapsed   = $cur_time - $time_ago;
$seconds    = $time_elapsed ;
$minutes    = round($time_elapsed / 60 );
$hours      = round($time_elapsed / 3600);
$days       = round($time_elapsed / 86400 );
$weeks      = round($time_elapsed / 604800);
$months     = round($time_elapsed / 2600640 );
$years      = round($time_elapsed / 31207680 );

// Seconds
if($seconds &amp;amp;lt;= 60){
    return &amp;quot;just now&amp;quot;;
}

//Minutes
else if($minutes &amp;amp;lt;=60){
    if($minutes==1){
        return &amp;quot;1 minute ago&amp;quot;;
    }
    else{
        return &amp;quot;$minutes minutes ago&amp;quot;;
    }
}

//Hours
else if($hours &amp;amp;lt;=24){
    if($hours==1){
        return &amp;quot;an hour ago&amp;quot;;
    }else{
        return &amp;quot;$hours hrs ago&amp;quot;;
    }
}

//Days
else if($days &amp;amp;lt;= 7){
    if($days==1){
        return &amp;quot;yesterday&amp;quot;;
    }else{
        return &amp;quot;$days days ago&amp;quot;;
    }
}

//Weeks
else if($weeks &amp;amp;lt;= 4.3){
    if($weeks==1){
        return &amp;quot;a week ago&amp;quot;;
    }else{
        return &amp;quot;$weeks weeks ago&amp;quot;;
    }
}

//Months
else if($months &amp;amp;lt;=12){
    if($months==1){
        return &amp;quot;a month ago&amp;quot;;
    }else{
        return &amp;quot;$months months ago&amp;quot;;
    }
}

//Years
else{
    if($years==1){
        return &amp;quot;1 year ago&amp;quot;;
    }else{
        return &amp;quot;$years years ago&amp;quot;;
    }
}
}
?>

After write this function we will have to call the function. First we will create a variable for date and then print it


$posted_time = "2020-27-02 20:20:20";

// For Print with timeago

echo timeAgo($posted_time); // timeAgo is function which had created eariler and $posted_time is variable where time has been stored.