1

i cannot multiplicate the simple string in arithmetic operation "*" adding mineutes to variable, testing with integers works fine, any idea. Thanks

$minu = intval("2");                                                                
$timestring = "00:02:42";

$futureTime = strtotime($timestring) + (60*2); // works fine adding two minutes
$futureTime = strtotime($timestring) + (60 * $minu); // doesn't work and returns same value

$formatTime = date("H:i:s", $futureTime);

echo $formatTime; /// 00:04:42 /// ok

//// NOW i concatenate and storage in DB like this value triming : "1".000412."000"
//// Operation no ejecute when (60 * $minu) with this output 00:02:42
4
  • echoing the right formatted value might help - ideone.com/ASpXpw Commented Sep 25, 2014 at 7:27
  • echo $formatTime. It gives correct result. Commented Sep 25, 2014 at 7:28
  • 1
    what is your expected output? both variable return same output link time = 1411603482 Commented Sep 25, 2014 at 7:33
  • Operation no ejecute when (60 * $minu) with this output 00:02:42, after i need concatenate to formated time in this format "1".$formatTime."000" triming :, the final objetive is 1000442000 Commented Sep 25, 2014 at 15:04

4 Answers 4

1

Result is correct:

   $minu = intval("2");                                                             
   $timestring = "00:02:42";

   $futureTime =  strtotime($timestring) + (60 * $minu);

   $formatTime = date("H:i:s", $futureTime);
   echo $formatTime; // 00:04:42
   echo $futureTime; //1411617882
Sign up to request clarification or add additional context in comments.

1 Comment

Now, i concatenate and storage result $formatTime2=date("His", $futureTime) with this command "1".$formatTime2."000" objetive is 1000442000. But fail when include variable $minu
0

Your code will be make the same result like my code below: And it make no mistake I think

 echo date("H:i:s", strtotime("00:02:42") + (60 * intval('2')));

Comments

0

try this:

$futureTime =  strtotime($timestring) + (60 * $minu);
$formatTime= DateTime::createFromFormat('H:i:s', $futureTime );

Comments

0

Easy fix, make sure the variables are correct ;) [You are echoing the incorrect one]

Personally I would use Carbon. It will have a you a LOT of headache in the future! https://github.com/briannesbitt/Carbon

Carbon Example:

$minutes = 2;
$time = '00:02:42'
$carbon = Carbon::parse($time)->addMinutes($minutes);
echo $carbon->format('H:i:s');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.