Add minutes to strtotime
Asked Answered
C

4

5

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?

Confabulation answered 19/11, 2013 at 2:0 Comment(0)
Z
24

You can do this:

strtotime("+{$min} minutes");
Zischke answered 19/11, 2013 at 2:2 Comment(1)
The second parameter should be an integer (i.e. a Unix timestamp). Only the first parameter can be a time string.Karankaras
S
11

There's not much to it:

echo strtotime("+40 minutes");

See it in action

Shyster answered 19/11, 2013 at 2:1 Comment(0)
K
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);
Karankaras answered 19/11, 2013 at 2:25 Comment(0)
B
1
$min = 40;

And i want to add it to a strotime formatted time

$strtTime = strtotime("+".$min." minutes", strtotime('now'));//eg +40 minutes 
Breakwater answered 4/5, 2016 at 8:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.