note 70818 modified in function.time by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 04:23:37 +0000 |
| Subject: | note 70818 modified in function.time by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142128@lists.php.net to get a copy of this message | ||
An improved version of my previous function:
<?php
function ago($timestamp){
$difference = time() - $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";
$text = "$difference $periods[$j] ago";
return $text;
}
?>
--was--
An improved version of my previous function:
<?
function ago($timestamp){
$difference = time() - $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";
$text = "$difference $periods[$j] ago";
return $text;
}
?>
http://php.net/manual/en/function.time.php