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
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: ???

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.