note 51030 deleted from language.operators.arithmetic by hholzgra

From: Date: Thu, 02 Aug 2012 15:03:59 +0000
Subject: note 51030 deleted from language.operators.arithmetic by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189800@lists.php.net to get a copy of this message
Note Submitter: areshankar at gmail dot com ---- 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; }

« previous php.notes (#189800) next »