function TimeAgo datefrom time_difference time datefrom years round ti

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function TimeAgo($datefrom) {
$time_difference = time()- ($datefrom) ;
$years = round($time_difference / 29030400 );
$months = round($time_difference / 2419200 );
$weeks = round($time_difference / 604800 );
$days = round($time_difference / 86400 );
$hours = round($time_difference / 3600 );
$minutes = round($time_difference / 60 );
$seconds = $time_difference;
if($years > 0) $str .= declension($years,array('год','года','лет')).' ';
if($months > 0) $str .= declension($months,array('месяц','месяца','месяцев')).' ';
if($weeks > 0) $str .= declension($weeks,array('неделя','недели','недель')).' ';
if($days > 0) $str .= declension($days,array('день','дня','дней')).' ';
if($hours > 0) $str .= declension($hours,array('час','часа','часов')).' ';
if($minutes > 0) $str .= declension($minutes,array('минута','минуты','минут')).' ';
if($seconds > 0) $str .= declension($seconds,array('секунда','секунды','секунд'));
return $str;
}