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 Link to comment https://forums.phpfreaks.com/topic/57088-displaying-rounded-time/ 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. Link to comment https://forums.phpfreaks.com/topic/57088-displaying-rounded-time/#findComment-282070 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.