Use of floor

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sandy1028
Forum Commoner
Posts: 60
Joined: Thu Jul 26, 2007 3:56 am

Use of floor

Post 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";
}
 
 
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Use of floor

Post 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;
Post Reply