Welcome aboard! We are happy you are here and wish you good net-raft!
<!DOCTYPE html>
<html lang="en-US">
<head>
</head>
<body>
<?php
function relativeDate($time, $now = null){
if (!isset($now)) {
$now = time();
}
$seconds = $now - $time;
$minutes = floor($seconds / 60);
$hours = floor($minutes / 60);
$days = floor($hours / 24);
$months = floor($days / 30);
$years = floor($days / 365);
if ($years >= 2) {
return $years . " years ago";
} elseif ($years == 1) {
return $years . " year ago";
} elseif ($months >= 2) {
return $months . " months ago";
} elseif ($months == 1) {
return $months . " month ago";
} elseif ($days >= 2) {
return $days . " days ago";
} elseif ($days == 1) {
return $days . " day ago";
} elseif ($hours >= 2) {
return $hours . " hours ago";
} elseif ($hours == 1) {
return $hours . " hour ago";
} elseif ($minutes >= 2) {
return $minutes . " minutes ago";
} elseif ($minutes == 1) {
return $minutes . " minute ago";
} elseif ($seconds > 0) {
return "a moment ago";
} else {
return "in the future";
}
}
?>
<?php
echo relativeDate(strtotime("2018-02-10"));
?>
</body>
</html>
The most helpful PHP solutions
detect browser phpPHP
Click to see more ...
4.9K
408
create QR code phpPHP
Click to see more ...
3.3K
289
create relative date phpPHP
Click to see more ...
2.4K
264
drag and drop upload file using phpPHP
Click to see more ...
2.9K
253
delete array item phpPHP
Click to see more ...
2.7K
245
detect ie phpPHP
Click to see more ...
1.8K
213
detect speed internet phpPHP
Click to see more ...
1.9K
198
get current url phpPHP
Click to see more ...
2.1K
197
get meta tag phpPHP
Click to see more ...
1.6K
193
Get real client country using php ?PHP
Click to see more ...
1.6K
181