-3

I have this $date variable.

$date   = DateTime::createFromFormat('D, d M Y H:i:s', $dates[1][0]); 

My question is how to have a $future date in the same format as the $date but add 5 minutes to it?

EnexoOnoma
  • 8,454
  • 18
  • 94
  • 179

2 Answers2

0

Refrence: Adding minutes to date time in PHP

$minutes_to_add = 5;

$time = new DateTime('2011-11-17 05:05');
$time->add(new DateInterval('PT' . $minutes_to_add . 'M'));

$stamp = $time->format('Y-m-d H:i');

Without Variable:

$time = new DateTime('2011-11-17 05:05');
$time->add(new DateInterval('PT' . '5' . 'M'));

$stamp = $time->format('Y-m-d H:i');

echo $stamp;
Community
  • 1
  • 1
Manwal
  • 23,450
  • 12
  • 63
  • 93
0

That should works :

$format = 'D, d M Y H:i:s';
$future = DateTime::createFromFormat($format, $dates[1][0]);
$future->add(new DateInterval('P5M'));
echo $future->format($format) . "\n";
Tom
  • 33
  • 6