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 Link to comment https://forums.phpfreaks.com/topic/57721-doing-math-with-timestamp/ 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 Link to comment https://forums.phpfreaks.com/topic/57721-doing-math-with-timestamp/#findComment-285767 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; ?> Link to comment https://forums.phpfreaks.com/topic/57721-doing-math-with-timestamp/#findComment-285777 Share on other sites More sharing options...
micah1701 Posted June 29, 2007 Share Posted June 29, 2007 echo date("H:i",$doseconds); Link to comment https://forums.phpfreaks.com/topic/57721-doing-math-with-timestamp/#findComment-285793 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 Link to comment https://forums.phpfreaks.com/topic/57721-doing-math-with-timestamp/#findComment-285794 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); ?> Link to comment https://forums.phpfreaks.com/topic/57721-doing-math-with-timestamp/#findComment-285813 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.