Add 5 minutes to current time in php

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?

Add 5 minutes to current time in php

Script47

13.8k4 gold badges43 silver badges61 bronze badges

asked Apr 10, 2011 at 0:42

2

$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! :)

answered Apr 10, 2011 at 0:46

FrantisekFrantisek

7,23515 gold badges56 silver badges99 bronze badges

Try this:

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

Alix Axel

148k91 gold badges390 silver badges493 bronze badges

answered Apr 10, 2011 at 0:46

BlenderBlender

279k51 gold badges424 silver badges487 bronze badges

$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

answered Sep 30, 2012 at 14:02

0

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

answered Mar 25, 2014 at 16:44

NidhinNidhin

1,80822 silver badges22 bronze badges

1

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

answered Apr 10, 2011 at 0:50

studioromeostudioromeo

1,56312 silver badges18 bronze badges

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

answered Apr 1, 2014 at 10:01

Add 5 minutes to current time in php

MaxEchoMaxEcho

14.1k6 gold badges78 silver badges88 bronze badges

more illustrative for simple and clear solution

    $date = '2011-04-8 08:29:49';
    $newtimestamp = strtotime($date. ' + 5 minute');//gets timestamp
    //convert into whichever format you need 
    $newdate = date('Y-m-d H:i:s', $newtimestamp);//it prints 2011-04-08 08:34:49

answered Aug 28, 2015 at 15:30

Add 5 minutes to current time in php

DeveloperDeveloper

3,6674 gold badges36 silver badges45 bronze badges

How to add 5 minutes to timestamp in php?

Example 1: PHP Add Minutes to Time.
index.php. $date = "10:10:05"; $newDate = date('H:i:s', strtotime($date. ' +10 minutes')); ... .
Output: 10:20:05..
index.php. $newDate = date('H:i:s', strtotime('+10 minutes')); echo $newDate; ?>.
Output: Read Also: PHP Add Hours to Datetime Example. 04:05:51. i hope it can help you....

How to add minutes to timestamp in php?

You could use strtotime() like this: $date = date('Y-m-d H:i:s', strtotime('now +60 minutes'));

How can I add minutes and minutes in PHP?

For this, you can use the strtotime() method. $anyVariableName= strtotime('anyDateValue + X minute'); You can put the integer value in place of X.

How to add hours and minutes to time in php?

PHP | DateTime add() Function The DateTime::add() function is an inbuilt function in PHP which is used to add an amount of time (days, months, years, hours, minutes and seconds) to the given DateTime object.