Jump to content

Need help with time calculations


mediabob

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.