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! Link to comment https://forums.phpfreaks.com/topic/106211-solved-calculate-hours-worked/ 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. Link to comment https://forums.phpfreaks.com/topic/106211-solved-calculate-hours-worked/#findComment-544417 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: ??? Link to comment https://forums.phpfreaks.com/topic/106211-solved-calculate-hours-worked/#findComment-544422 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> Link to comment https://forums.phpfreaks.com/topic/106211-solved-calculate-hours-worked/#findComment-544426 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! Link to comment https://forums.phpfreaks.com/topic/106211-solved-calculate-hours-worked/#findComment-544435 Share on other sites More sharing options...
Alexhoward Posted May 18, 2008 Author Share Posted May 18, 2008 Thankyou! it works a treat!! Link to comment https://forums.phpfreaks.com/topic/106211-solved-calculate-hours-worked/#findComment-544445 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.