note 51030 added to language.operators.arithmetic
| From: | areshankaratgmaildotcom at osu1 dot php dot net | Date: | Thu, 17 Mar 2005 10:40:46 +0000 |
| Subject: | note 51030 added to language.operators.arithmetic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86579@lists.php.net to get a copy of this message | ||
Most of the mail services/bulletin boards display the time when the message was posted or the mail
was received in the form - 3 days ago, 15 mins ago etc.
Here is a nifty little PHP function which does the same by basically combining the usage of
"/" and "%" operators.
You need to pass the unix timestamp of the time when the message was posted to the function.
function intervalCalc($postedtime)
{
$now = time();
$interval_secs = $now - $postedtime;
if ($interval_secs > 86400)
{
$interval = (($interval_secs - ($interval_secs%86400))/86400);
$interval.= " days ago";
}
elseif ($interval_secs > 3600)
{
$interval = ($interval_secs - ($interval_secs%3600)/3600);
$interval.= " hours ago";
}
elseif ($interval_secs > 60)
{
$interval = ($interval_secs - ($interval_secs%60)/60);
$interval.= " minutes ago";
}
return $interval;
}
----
Manual Page -- http://www.php.net/manual/en/language.operators.arithmetic.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51030
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51030&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51030&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51030&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51030&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51030&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51030&report=yes
Search -- http://master.php.net/manage/user-notes.php