Space Cowboy Posted March 24, 2009 Share Posted March 24, 2009 Hi there, Im creating a job sheet system, where people enter how many minutes they have spent on a job. The minutes are totaled up and im left with a total like: 465 (minutes). I need something that will break that down into hours. (465 minutes is equal to 7 hours and 45 mins). If I try this calculation: 465 / 60 it equals 7.75. It needs to be 7.45 and I cant find the answer anywhere Any help would be massively appreciated Link to comment https://forums.phpfreaks.com/topic/150858-solved-how-can-i-calculate-hours-from-minutes/ Share on other sites More sharing options...
Mchl Posted March 24, 2009 Share Posted March 24, 2009 http://www.php.net/manual/en/language.operators.arithmetic.php $totalMinutes = 465; $hours = (int)($totalMinutes / 60); $minutes = $totalMinutes % 60; echo $hours.":".$minutes; not tested, but should work [edit] some ordering in variable names Link to comment https://forums.phpfreaks.com/topic/150858-solved-how-can-i-calculate-hours-from-minutes/#findComment-792468 Share on other sites More sharing options...
Yesideez Posted March 24, 2009 Share Posted March 24, 2009 $hours=floor($totalminutes / 60); $minutes=$totalminutes % 60; If the values don't appear 100% try ceil() instead of floor() Link to comment https://forums.phpfreaks.com/topic/150858-solved-how-can-i-calculate-hours-from-minutes/#findComment-792469 Share on other sites More sharing options...
Space Cowboy Posted March 24, 2009 Author Share Posted March 24, 2009 brilliant, thanks guys, these both work :-) Link to comment https://forums.phpfreaks.com/topic/150858-solved-how-can-i-calculate-hours-from-minutes/#findComment-792489 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.