Jump to content

[SOLVED] Calculate hours worked


Alexhoward

Recommended Posts

Hi Guys,

 

i'm trying to create a page for employees to input their hours worked.

 

the part i'm trying to calculate consists of two input boxes:

 

Start Time:

Finish Time:

 

i have made these selectable from a list a list box, in the format 00:00, in 15 minute intervals, in 24hr.

 

however, i'm not sure on how to calculate the total hours....?

 

sometimes we may work from 18:00 to 02:00

 

does anyone have any ideas?

 

thanks in advance!

 

 

Link to comment
https://forums.phpfreaks.com/topic/106211-solved-calculate-hours-worked/
Share on other sites

Hi,

 

Thanks for the reply

 

yes, they will be entering:

 

Date: day(dropdown 1-31), month(dropdown Jan-Dec), year(dropdown 08 - 15)

Location: (textbox)

Start Time: (listbox 00:00 - 23:45)

End Time : (listbox 00:00 - 23:45)

Hours Worked: ???

If end time < start time, add 24 hours to end time

 

Hrs worked = end time - start time

 

<?php
$st = $_GET['stime'];
$et = $_GET['etime'];
list ($sh, $sm) = explode (':', $st);
list ($eh, $em) = explode (':', $et);
if ($et < $st)  $eh += 24; 
$minsWorked = ($eh-$sh) * 60 + ($em - $sm);
echo "Hours worked ", number_format($minsWorked/60, 2); 
?>
<form>
Start <input type="text" name="stime" size="5"> hh:mm <br/>
End <input type="text" name="etime" size="5"> hh:mm <br/> 
<input type="submit" name="sub" value="Submit">
</form>

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.