This is the strptime to human time function...
PHP:
function humanTiming($tm,$rcs = 0)
{
$cur_tm = time(); $dif = $cur_tm-$tm;
$pds = array('second','minute','hour','day','week','month','year','decade');
$lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600);
for($v = sizeof($lngh)-1; ($v >= 0)&&(($no = $dif/$lngh[$v])<=1); $v--); if($v < 0) $v = 0; $_tm = $cur_tm-($dif%$lngh[$v]);
$no = floor($no); if($no <> 1) $pds[$v] .='s'; $x=sprintf("%d %s ",$no,$pds[$v]);
if(($rcs == 1)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= time_ago($_tm);
return $x;
}
The function works just fine, but when I pass a MySQL timestamp through it reaches an error and displays and unrealistic date like 40 years ago...
If I send a MySQL timestamp to the function ex:
2015-02-25 12:23:34
This is the the error I reach it returns this
4 decades
use strtotime('2015-02-25 12:23:34')
that should do the trick.
strtotime converts a string to a unix timestamp, which is required in your function.
If you pass a string to that function like 2015-02-25 12:23:34
, it converts it to 0 as the unix timestamp. 0 seconds since Jan 01 1970, so that over 4 decades ago. Some documentation on this here http://unixtimestamp.com