rodin Posted June 25, 2007 Share Posted June 25, 2007 Hi All, Looking to see if there is a way to round time to the nearest half hour, so no matter what time is displayed, the nearest half hour is displayed. ie: If time displayed is 1:12AM - regardless, round it up to 1:30AM -- 1:01AM still rounds to 1:30AM -- Is this possible? Was unable to find anything on google to do this.. Any help greatly appreciated Quote Link to comment Share on other sites More sharing options...
Orio Posted June 25, 2007 Share Posted June 25, 2007 I would do something like this (haven't tested it tho): <?php $min = date("i"); $hour = date("g"); if($min > 30 || $min == 0) { if($min != 0) { $hour++; $hour = ($hour > 12) ? 1 : $hour; } $final = $hour.":00 ".date("A"); } else $final = $hour.":30 ".date("A"); ?> Orio. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.