datetime - How to display time in x days ago in php - Stack Overflow

PHOTO EMBED

Fri Feb 05 2021 11:31:47 GMT+0000 (UTC)

Saved by @Saymon15 #php

// intval() - http://php.net/manual/en/function.intval.php

$seconds_ago = (time() - strtotime('2014-01-06 15:25:08'));

if ($seconds_ago >= 31536000) {
    echo "Seen " . intval($seconds_ago / 31536000) . " years ago";
} elseif ($seconds_ago >= 2419200) {
    echo "Seen " . intval($seconds_ago / 2419200) . " months ago";
} elseif ($seconds_ago >= 86400) {
    echo "Seen " . intval($seconds_ago / 86400) . " days ago";
} elseif ($seconds_ago >= 3600) {
    echo "Seen " . intval($seconds_ago / 3600) . " hours ago";
} elseif ($seconds_ago >= 60) {
    echo "Seen " . intval($seconds_ago / 60) . " minutes ago";
} else {
    echo "Seen less than a minute ago";
}
content_copyCOPY

https://stackoverflow.com/questions/27330650/how-to-display-time-in-x-days-ago-in-php/27330857