note 42345 modified in function.floor by danbrown

From: Date: Thu, 10 Mar 2011 15:22:47 +0000
Subject: note 42345 modified in function.floor by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177766@lists.php.net to get a copy of this message
For calculating the number of days, hours, minutes and seconds to an event. <?php $then = date(mktime(8,0,0,6,25,2004)); //remember that mktime is hour,min,sec,month,day,year $now = date("U"); // "U" is the number of seconds since the epoch, equivilant to using "YmdHis" $time = $then - $now; //gets the number of seconds between now and the event $days = floor($time/86400); //rounds down to the whole number, in this case # of days echo $days." Days"; $time = $time - ($days*86400); //leaves you with the amount of time ramaining after subtracting the days $hours = floor($time/3600); //rounds down to the whole number, in this case # of hours echo $hours." Hours"; $time = $time - ($hours*3600); //leaves you with the amount of time ramaining after subtracting the hours $min = floor($time/60); //rounds down to the whole number, in this case # of minutes echo $min." Minutes"; $sec = $time - ($min*60); //leaves you with the amount of time ramaining after subtracting the minutes which is equivilant to the remainins seconds echo $sec." Seconds"; ?> --was-- For calculating the number of days, hours, minutes and seconds to an event. <? $then = date(mktime(8,0,0,6,25,2004)); //remember that mktime is hour,min,sec,month,day,year $now = date("U"); // "U" is the number of seconds since the epoch, equivilant to using "YmdHis" $time = $then - $now; //gets the number of seconds between now and the event $days = floor($time/86400); //rounds down to the whole number, in this case # of days echo $days." Days"; $time = $time - ($days*86400); //leaves you with the amount of time ramaining after subtracting the days $hours = floor($time/3600); //rounds down to the whole number, in this case # of hours echo $hours." Hours"; $time = $time - ($hours*3600); //leaves you with the amount of time ramaining after subtracting the hours $min = floor($time/60); //rounds down to the whole number, in this case # of minutes echo $min." Minutes"; $sec = $time - ($min*60); //leaves you with the amount of time ramaining after subtracting the minutes which is equivilant to the remainins seconds echo $sec." Seconds"; ?> http://php.net/manual/en/function.floor.php

« previous php.notes (#177766) next »