Hello.
I am looking for a function to convert TIMESTAMP such as “1414792807”
to this format:
“one day, 5 minutes ago”
or
“2 years, 3 months ago”
and not only “2 years”.
Anyone knows any PHP function that might be good for this kind of use?
Thanks in advance.
Try this (like in my site - but in russian)
function get_elapsed_time($ts)
{
$mins = floor((gmtime() - $ts)/60);
$hours = floor($mins/60);
$mins -= $hours*60;
$days = floor($hours/24);
$hours -= $days*24;
$weeks = floor($days/7);
$days -= $weeks*7;
if ($weeks == 1)
$w = "week";
elseif ($weeks > 1 && $weeks < 5)
$w = "weeks";
elseif ($weeks > 4)
$w = "weeks";
if ($weeks >= 1){
$we = "".$weeks." ".$w."";
}
if ($days == 1)
$d = "day";
elseif ($days > 1 && $days < 5)
$d = "day";
elseif ($days > 4)
$d = "days";
if ($days >= 1 ){
$da = "".$days." ".$d."";
}
if ($hours == 1)
$h = "hour";
elseif ($hours > 1 && $hours < 5)
$h = "hour";
elseif ($hours > 4)
$h = "hours";
if ($hours >= 1){
$ho = "".$hours." ".$h."";
}
if ($mins > 10 && $mins < 15)
$m = "minute";
elseif (($mins%10) == 1)
$m = "minute";
elseif (($mins%10) > 1 && ($mins%10) < 5)
$m = "minutes";
elseif (($mins%10) > 4)
$m = "minute";
if ($mins >= 1){
$mi = "".$mins." ".$m."";
}else{
$mi = "less than a minute";
}
if ($weeks || $days || $hours || $mins)
return $we." ".$da." ".$ho." ".$mi;
}
xMog
November 1, 2014, 3:03pm
3
system
Closed
January 31, 2015, 10:07pm
4
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.