newphpbees Posted February 2, 2012 Share Posted February 2, 2012 Hi.. I got an issue in getting the total time. I have this code to get the sum of total time: $result = mysql_query("INSERT INTO payroll.casual_hours(EMP_NO, Hours) SELECT EMP_NO, sec_to_time(SUM(time_to_sec(Rendered))) FROM payroll.casual_att WHERE DATE_FORMAT(LOGOUT, '%W') IN ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') GROUP BY EMP_NO") or die(mysql_error()); Rendered: 09:00:00 09:00:00 09:00:00 08:00:00 08:00:00 07:48:00 and the result of this is 50:48 but I need result is 50:80 the minutes is divided to 60 Is there any way to get the 50:80 result. Thank you so much.. Quote Link to comment https://forums.phpfreaks.com/topic/256236-problem-in-time/ Share on other sites More sharing options...
Pikachu2000 Posted February 2, 2012 Share Posted February 2, 2012 Why do you think the result should be 50:80? The total is clearly correct at 50:48 Quote Link to comment https://forums.phpfreaks.com/topic/256236-problem-in-time/#findComment-1313597 Share on other sites More sharing options...
newphpbees Posted February 2, 2012 Author Share Posted February 2, 2012 In payroll minutes was divided into 60. i tried this: $TotHours = substr($Hours, 0, 3); $Minutes = substr($Hours,4,2); $Minutes = substr($Hours,3,2); $Minutes_Convert = ($Minutes / 60); $Minutes_Convert = number_format($Minutes_Convert, 2, '.', ''); $Hours = $TotHours + $Minutes_Convert; but i encountered problem when TotHours = 100 the substr was not capable. Quote Link to comment https://forums.phpfreaks.com/topic/256236-problem-in-time/#findComment-1313598 Share on other sites More sharing options...
newphpbees Posted February 2, 2012 Author Share Posted February 2, 2012 Is it possible that first i only get the total hours and I save it in one field? then i add one field to put the total minutes? from sum of Hours? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/256236-problem-in-time/#findComment-1313602 Share on other sites More sharing options...
Proletarian Posted February 2, 2012 Share Posted February 2, 2012 If you're going for percentage of time, rather than actual minutes, you might need to convert your hours into minutes, then add those to the remainer minutes, then divide it all by 60. i.e., 04h30m = 240 + 30 = 270 / 60 = 4.5 And it would be a "." not a ":" when you're displaying the hours. Quote Link to comment https://forums.phpfreaks.com/topic/256236-problem-in-time/#findComment-1313607 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.