<?php
function ago($timestamp)
$difference = time() – strtotime($timestamp);
$periods = array(‘second’, ‘minute’, ‘hour’, ‘day’, ‘week’, ‘month’, ‘years’, ‘decade’);
$lengths = array(’60′, ’60′, ’24′, ’7′, ’4.35′, ’12′, ’10′);
for($j = 0; $difference >= $lengths[$j]; $j++) $difference /= $lengths[$j];
$difference = round($difference);
if($difference != 1) $periods[$j] .= “s”;
return “$difference $periods[$j] ago”;
echo ago(’2013-11-28 09:50:28′);
?>
PHP Time ago like facebook function
function ago($timestamp)
$difference = time() – strtotime($timestamp);
$periods = array(‘second’, ‘minute’, ‘hour’, ‘day’, ‘week’, ‘month’, ‘years’, ‘decade’);
$lengths = array(’60′, ’60′, ’24′, ’7′, ’4.35′, ’12′, ’10′);
for($j = 0; $difference >= $lengths[$j]; $j++) $difference /= $lengths[$j];
$difference = round($difference);
if($difference != 1) $periods[$j] .= “s”;
return “$difference $periods[$j] ago”;
echo ago(’2013-11-28 09:50:28′);
?>
PHP Time ago like facebook function
No comments:
Post a Comment
Please mention your comments.......