Skip to content

Tag: subtraction

PHP negative time calculation

If I add 1 hour and 35 minutes in PHP and subtract 4 hours, I get a remaining time of -3 hours and 30 minutes. But correct would be -2 hours and 30 minutes. Where’s the mistake? Answer $minutes – floor($minutes/60) is positive. So what you’re getting is -3 hours plus 30 minutes, which is -2:30. Yo…