hellouthere Posted March 31, 2007 Share Posted March 31, 2007 Somebody on thtis forum as written me this function for converting hours in the format 00:00:00 into decimal hours <?php function timeToHours($time) { //Split time into an array $timeAry = explode (":",$time); //Convert into a decimal equiv for hours //Ex: 1:30:00 = 1.5 $hours = 0; foreach($timeAry as $exp => $value) { $exp += (3-count($timeAry)); $hours += $value / pow(60,$exp); } return $hours; } ?> I now need to do the inverse operation (decimal hours --> 00:00:00) could anybody help out? thanks in advance! Link to comment https://forums.phpfreaks.com/topic/45048-solved-time/ Share on other sites More sharing options...
AndyB Posted March 31, 2007 Share Posted March 31, 2007 hmm, toughie. There are 3600 seconds in an hour so convert your decimal hours to seconds (that to minutes and a remainder in seconds ...) Link to comment https://forums.phpfreaks.com/topic/45048-solved-time/#findComment-218687 Share on other sites More sharing options...
hellouthere Posted March 31, 2007 Author Share Posted March 31, 2007 Thankyou andy, kicked me just at the right time, not in the right frame of mind due to family death and not thinking straight... Link to comment https://forums.phpfreaks.com/topic/45048-solved-time/#findComment-218704 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.