Hi everybody,
I have a new request for you,
How could I have this kind of date format (time elapsed format) :
Posted 1 week ago
Posted 1 hour ago
Posted now
…
Something existing ?
It should be on the afterFind() in the AR
My Model is :
Comment
id
text
userId
createTime
EDIT
I found this code, but it showing everytime 44 year
function time_elapsed_string() {
$etime = time() - $this->createdTime;
if ($etime < 1) {
return '0 seconds';
}
$a = array( 12 * 30 * 24 * 60 * 60 => 'year',
30 * 24 * 60 * 60 => 'month',
24 * 60 * 60 => 'day',
60 * 60 => 'hour',
60 => 'minute',
1 => 'second'
);
foreach ($a as $secs => $str) {
$d = $etime / $secs;
if ($d >= 1) {
$r = round($d);
return $r . ' ' . $str . ($r > 1 ? 's' : '');
}
}
}
EDIT RESOLVED :
It Works I just deleted my afterFind() method