Alexhoward Posted May 18, 2008 Share Posted May 18, 2008 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! Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 18, 2008 Share Posted May 18, 2008 I would say it depends on what data you are getting from the user. Are you getting the date they worked too? Maybe if we saw your form it would help. Quote Link to comment Share on other sites More sharing options...
Alexhoward Posted May 18, 2008 Author Share Posted May 18, 2008 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: ??? Quote Link to comment Share on other sites More sharing options...
Barand Posted May 18, 2008 Share Posted May 18, 2008 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> Quote Link to comment Share on other sites More sharing options...
Alexhoward Posted May 18, 2008 Author Share Posted May 18, 2008 Excellent! thankyou, i shall play with the code and report back thanks again! Quote Link to comment Share on other sites More sharing options...
Alexhoward Posted May 18, 2008 Author Share Posted May 18, 2008 Thankyou! it works a treat!! Quote Link to comment 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.