Jump to content

Time calculations


perficut

Recommended Posts

I am trying to find a way to calculate jobsite time but have a few small problems.  1st is I would like to use the 24hour time format if possible.  Second, I cant get the program to realise the difference between 11pm and 2am, and to know that there is 3 hours difference.

 

Most of our work is done during the evening and a start time generally is before midnight, with an ending time after midnight.  Any ideas?

 

<? $start_time = $_REQUEST['start_time']; $end_time = $_REQUEST['end_time']; $action = $_REQUEST['action']; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<html> 
<body> 
<h3>Parse Times</h3> 
<form action="<?= $_SERVER['PHP_SELF'] ?>"> Enter the start time (hours:minutes) 
<input type="text" name="start_time" value="<?= $start_time ?>" size="60"> <br/>  Enter the end time (hours:minutes) 
<input type="text" name="end_time" value="<?= $end_time ?>" size="60"> <br/> 
<input type="submit" value="Go!"> <br/>

<input type="hidden" name="action" value="go"> </form> <hr> 

<? if($action && ($action == "go")){
     list($hours, $minutes) = split(':', $start_time);     $startTimestamp = mktime($hours, $minutes); 
     list($hours, $minutes) = split(':', $end_time);     $endTimestamp = mktime($hours, $minutes);  
$seconds = $endTimestamp - $startTimestamp;     
$minutes = ($seconds / 60) % 60;     
$hours = round($seconds / (60 * 60)); 

echo "Time On Job Site: <b>$hours</b> hours and <b>$minutes</b> minutes"; } ?> 

</body> 
</html>

Link to comment
https://forums.phpfreaks.com/topic/134168-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.