note 52740 added to function.fmod
| From: | RyanMeans at osu1 dot php dot net | Date: | Wed, 11 May 2005 13:15:36 +0000 |
| Subject: | note 52740 added to function.fmod | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-89258@lists.php.net to get a copy of this message | ||
If your given a number of seconds and you want to turn it into Days, hours, minutes, and seconds:
(this is very useful when using the Unix Time Epoch to find the difference from one time to the
other)
For Example:
I posted in a bb at one date.. when I post a Unix Time Epoch was marked..
Then When I go back and view it again 2 weeks later I generate the Unix Time Epoch for the current
time.
Then take the current time - the posting time, this gives the number of seconds since the post.
Then use the below equations to get days, hours, minutes, and seconds since the post was made:
<?PHP
$totalsec=XXXXXXX; //Replace the X's with a int value of seconds
$daysarray = explode(".", ($totalsec/86400));
$days = $daysarray[0];
$partdays = fmod($totalsec, 86400);
$hoursarray = explode(".", ($partdays/3600));
$hours = $hoursarray[0];
$parthours = fmod($partdays, 3600);
$minarray = explode(".", ($parthours/60));
$min = $minarray[0];
$sec = fmod($parthours, 60);
echo "days " . $days . "<br>";
echo "hours " . $hours . "<br>";
echo "minutes " . $min . "<br>";
echo "seconds " . $sec . "<br>";
?>
----
Manual Page -- http://www.php.net/manual/en/function.fmod.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52740
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52740&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52740&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52740&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52740&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52740&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52740&report=yes
Search -- http://master.php.net/manage/user-notes.php