Shawn Sonnier
Shawn Sonnier

Reputation: 533

Add minutes to strtotime

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?

Upvotes: 5

Views: 53836

Answers (4)

Ugokoli
Ugokoli

Reputation: 91

$min = 40;

And i want to add it to a strotime formatted time

$strtTime = strtotime("+".$min." minutes", strtotime('now'));//eg +40 minutes 

Upvotes: 1

gen_Eric
gen_Eric

Reputation: 227180

You can do this:

strtotime("+{$min} minutes");

Upvotes: 24

Sverri M. Olsen
Sverri M. Olsen

Reputation: 13263

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);

Upvotes: 3

John Conde
John Conde

Reputation: 219794

There's not much to it:

echo strtotime("+40 minutes");

See it in action

Upvotes: 11

Related Questions