mediabob Posted March 22, 2011 Share Posted March 22, 2011 Hi, I am writing an application that tracks productivity in units per hour, so much of it involves working with time. So basically the person enters a start time, an end time, and there is a field to account for time not on the project (breaks, lunch, etc). Basically they way I have done it, to make it simple, is that in the form real times are entered and stored in the database (in 24 hour format). So, to calculate the units per hour, it pulls the time from the database, converts it to minutes, and works this calculation: $result = (($end_time - $start_time) - $breaks);// to get the total minutes on the project, (by this time is has been converted to minutes) $fuph = (($uph / $result) * 60); //and divide the units worked by the minutes worked on them and multiply by 60 OK, this works great except for one thing... when the shift crosses midnight.... One shift is 8pm - 8am, so say a project starts at 11:33PM (23:33) and runs until 1:15AM (01:15), it fouls up the calculation. I know I need to take one more step here to account for that... but at this point i'm lacking on sleep and can't wrap my head around it... so some help would be appreciated. Thanks! Link to comment https://forums.phpfreaks.com/topic/231426-need-help-with-time-calculations/ Share on other sites More sharing options...
kenrbnsn Posted March 22, 2011 Share Posted March 22, 2011 Use the date & time and convert that into seconds with the strtotime() function. This way the end time in seconds will always be larger than the start time. Ken Link to comment https://forums.phpfreaks.com/topic/231426-need-help-with-time-calculations/#findComment-1191007 Share on other sites More sharing options...
mediabob Posted March 22, 2011 Author Share Posted March 22, 2011 Thanks Ken, that was the solution I needed. Sometimes the most obvious solutions evade us Link to comment https://forums.phpfreaks.com/topic/231426-need-help-with-time-calculations/#findComment-1191044 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.