How to add 5 minutes to current datetime on php < 5.3

104,445

Solution 1

$date = '2011-04-8 08:29:49';
$currentDate = strtotime($date);
$futureDate = $currentDate+(60*5);
$formatDate = date("Y-m-d H:i:s", $futureDate);

Now, the result is 2011-04-08 08:34:49 and is stored inside $formatDate

Enjoy! :)

Solution 2

Try this:

echo date('Y-m-d H:i:s', strtotime('+5 minutes', strtotime('2011-04-8 08:29:49')));

Solution 3

$expire_stamp = date('Y-m-d H:i:s', strtotime("+5 min"));
$now_stamp    = date("Y-m-d H:i:s");

echo "Right now: " . $now_stamp;
echo "5 minutes from right now: " . $expire_stamp;

Results in:

2012-09-30 09:00:03

2012-09-30 09:05:03

Solution 4

For adding

$date = new DateTime('2014-02-20 14:20:00');
$date->add(new DateInterval('P0DT0H5M0S'));
echo $date->format('Y-m-d H:i:s');
It add 5minutes

For subtracting

$date = new DateTime('2014-02-20 14:20:00');
$date->sub(new DateInterval('P0DT0H5M0S'));
echo $date->format('Y-m-d H:i:s');

It subtract 5 minutes

Solution 5

If i'm right in thinking.

If you convert your date to a unix timestamp via strtotime(), then just add 300 (5min * 60 seconds) to that number.

$timestamp = strtotime($date) + (5*60)

Hope this helps

Share:
104,445

Related videos on Youtube

beginner
Author by

beginner

Updated on July 09, 2022

Comments

  • beginner
    beginner almost 2 years

    I want to add 5 minutes to this date: 2011-04-8 08:29:49

    $date = '2011-04-8 08:29:49';
    

    When I use strtotime I am always getting 1970-01-01 08:33:31

    How do I add correctly 5 minutes to 2011-04-8 08:29:49?

    • beginner
      beginner about 13 years
      date("Y-m-d H:i:s", strtotime('+5 minutes', $currenttime))

Related