jester626 Posted June 29, 2007 Share Posted June 29, 2007 OK, got a DB with TimeIn and TimeOut Fields, they are set up as INT and am using strtotime when these fields are populated. I can get the math to find out the amount of time allotted between the two times <SNIPPET> $doseconds = $row_getLastPunch['TimeOut'] - $row_getLastPunch['TimeIn'] </SNIPPET> Now I know to take the number and divide by 60 to get the minutes, and then another 60 to get the hours. here is where my problem starts and my skill level stops. Say I have a final answer that breaks down to 98 minutes (5880 seconds) when I go to get the hours (98 divide by 60) I get '1.6333~ hours' which is correct math, I would rather it display '1:38 hours' or something close to that. Any help and assistance would be greatly appreciated. Jester Quote Link to comment Share on other sites More sharing options...
Yesideez Posted June 29, 2007 Share Posted June 29, 2007 Try using the % operand as it will give you the remainder of a division. You can also play with floor(), ceil() and intval() to get the integer values of the division. Examples: 120 % 60=0 90 % 60=30 Quote Link to comment Share on other sites More sharing options...
Yesideez Posted June 29, 2007 Share Posted June 29, 2007 Thinking a bit more about it I'd try something like this: <?php $totalseconds=$timeout-$timein; $minutes=floor($totalseconds/60); $seconds=$totalseconds % 60); echo 'Time is '.$minutes.':'.$seconds; ?> Quote Link to comment Share on other sites More sharing options...
micah1701 Posted June 29, 2007 Share Posted June 29, 2007 echo date("H:i",$doseconds); Quote Link to comment Share on other sites More sharing options...
Yesideez Posted June 29, 2007 Share Posted June 29, 2007 Hahaha how could I forget that method? *oh the shame* lol Quote Link to comment Share on other sites More sharing options...
micah1701 Posted June 29, 2007 Share Posted June 29, 2007 when i test my own method locally i had to use gmdate() because my server is off by 7 hours. if you are getting the wrong results try: <?php echo gmdate("H:i:s",$totalseconds); ?> 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.