4

If i have a varible

// in minutes
$min = 40;

And i want to add it to a strotime formatted time

$strtTime = $strtotime('now') + $min; 

whats the correct way to do this?

Shawn Sonnier
  • 513
  • 5
  • 10
  • 28

4 Answers4

22

You can do this:

strtotime("+{$min} minutes");
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
10

There's not much to it:

echo strtotime("+40 minutes");

See it in action

John Conde
  • 217,595
  • 99
  • 455
  • 496
3

Well, look at the documentation. It tells you how to use the function.

$future = strtotime('+40 minutes');

You can also be a little more concrete and include where to start from.

$future = strtotime('now + 40 minutes');

While the above is a lot easier you could also do it manually. It just involves some basic arithmetic:

$now     = time(); // Seconds since 1970-01-01 00:00:00
$minutes = 40;
$seconds = ($minutes * 60); // 2400 seconds
$future  = ($now + $seconds);
Sverri M. Olsen
  • 13,055
  • 3
  • 36
  • 52
1
$min = 40;

And i want to add it to a strotime formatted time

$strtTime = strtotime("+".$min." minutes", strtotime('now'));//eg +40 minutes 
Ugokoli
  • 91
  • 1
  • 4