D
D
Dmitry2014-03-09 20:04:32
PHP
Dmitry, 2014-03-09 20:04:32

How to add dynamic date to timestamp?

Hello!
There was a problem, and something I can not understand how to solve it.
It is required to dynamically add a certain number of hours or minutes to the current timestamp.
I have:

foreach ($items as $item) {

   $time = strtotime(date("d-m-Y H:i:s", time()+3600));

}

Accordingly, for each $item, you need to add your own time, namely, add one hour, two or three, etc.
Tell me how to implement this?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Rpsl, 2014-03-09
@muldy

Why is strtotime here? You apparently tried to write:

foreach( $items as $item ) {
   $time = time() + 3600;
}

You can also use DateTime objects , it just has a method for adding an interval to a specific time.

S
svd71, 2014-03-09
@svd71

$time = strtotime('+1 hour');

A
Alexander Gubarev, 2014-03-09
@AlexGx

You most likely have an error in the body of the loop. Not a telepath, but most likely it should be something like this:

foreach ($items as $item) {
   $item = strtotime(date("d-m-Y H:i:s", time()+3600));
}

or
foreach ($items as $item) {
   $item['time'] = strtotime(date("d-m-Y H:i:s", time()+3600));
}

D
Dmitry, 2014-03-11
@muldy

Thanks to everyone for the response, I solved the problem with $time = time() + 3600;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question