The example in this article describes the functional usage of PHP before a given time is computed. Share to everyone for your reference. Specifically as follows:
This is given a time to calculate how long ago this time, for example: 2 days ago, 1 years ago
<?php function Prettydate ($date) {$time = Strtotime ($date);
$now = time ();
$ago = $now-$time;
if ($ago <) {$when = round ($ago); $s = ($when = = 1)? "
Second ":" Seconds ";
return "$when $s ago";
}elseif ($ago < 3600) {$when = round ($ago/60); $m = ($when = = 1)? "
Minute ":" Minutes ";
return "$when $m ago";
}elseif ($ago >= 3600 && $ago < 86400) {$when = round ($ago/60/60); $h = ($when = = 1)? "
Hour ":" Hours ";
return "$when $h ago";
}elseif ($ago >= 86400 && $ago < 2629743.83) {$when = round ($ago/60/60/24); $d = ($when = = 1)? "
Day ": The Days";
return "$when $d ago";
}elseif ($ago >= 2629743.83 && $ago < 31556926) {$when = round ($ago/60/60/24/30.4375); $m = ($when = = 1)? "
Month ":" Months ";
return "$when $m ago";
}else{$when = round ($ago/60/60/24/365); $y = ($when = = 1)? "
Year ":" Years ";
return "$when $y ago"; } Echo prettydate ("2012-07-2212:23:45 ")."
<br/> "; Echo prettydate ("2010-11-12 22:25:45"). "
<br/> "; Echo prettydate ("2012-01-01 01:00:00"). "
<br/> "; Echo prettydate ("2001-05-30 00:00:00"). " <br/> ";
I hope this article will help you with your PHP programming.