1

i got a simple question for some, but not so simple for me.

I want to add a defined amount of minutes to a defined time. It is a ticket penalty system, and there is a remove function, which are going to be disabled after a certain amount of time.

My code right now is:

$clock           = date("H:i", time());
$penaltyTime     = $getInfo["time"];
$allowedTime     = $getInfo["allowed"];
$finalTime       = $penaltyTime + $allowedTime; ???

Let us say that penaltyTime is 22:00 and allowedTime is 5, how can i then add the 5 minutes to 22:00, so i have a final variable called $finalTime, where the value is 22:05.

Thanks in advance.

Ismail
  • 253
  • 1
  • 4
  • 19
  • You're looking for [strtotime()](http://php.net/manual/en/function.strtotime.php) function – umka Jun 16 '15 at 21:32
  • Yeah but that gives me a 10 digit number, and i dont know how to convert it back to H:i format again – Ismail Jun 16 '15 at 21:33
  • 1
    hint: the return value of time() is a rather similar 10 digit number ;-) – VolkerK Jun 16 '15 at 21:34
  • [Convert H:i:s to seconds](http://stackoverflow.com/a/20874702/67332) + add X seconds (minutes * 60) + [convert seconds back to H:i:s](http://stackoverflow.com/a/20870843/67332). – Glavić Jun 17 '15 at 05:40

1 Answers1

0

Next is the solution to your problem. The time is first converted to a "big number", add the desired time, then converted it back to "normal" time:

<?php

$penaltyTime = "22:00";
$allowedTime = 5;

$finalTime = strtotime( $penaltyTime ) + ($allowedTime * 60);
echo gmdate( "H:i:s",$finalTime );

?>