Page 1 of 1

Use of floor

Posted: Thu Jan 31, 2008 12:11 am
by sandy1028
Hi,

I have a code below I should make hour and minutes as 00:00, 01:00

If the current time is 01:23 how to use floor and make it 01:00

Code: Select all

 
$timeincr=3600;
 
$time_interval=array();
$t=time();
$t=floor($t/$timeincr)*$timeincr;
$t=$t-5184600;
 
$date=date("m-d-Y",$t);
for($i=0;$i<24;$i++){
$ti=date("H:i",$t+$i*$timeincr);
 
array_push($time_interval,$ti);
}
for($i=0;$i<=count($time_interval);$i++){
print $time_interval[$i]."\n";
}
 
 

Re: Use of floor

Posted: Thu Jan 31, 2008 12:18 am
by Chris Corbyn
Untested:

Code: Select all

$time = '01:23';
 
$chunks = explode(':', $time);
 
$flooredTime = $chunks[0] . ':' . str_pad(floor($chunks[1], 2, '0', STR_PAD_LEFT));
 
echo $flooredTime;