php datetime add hours code example

Example 1: php add hours to current date

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

Example 2: how to add hour minute seconds in php datetime

date('Y-m-d H:i',strtotime('+1 hour +20 minutes',strtotime($start)));

Example 3: add 1 day php datetime

$date = new DateTime('2000-01-01');
$date->add(new DateInterval('P1D'));

Example 4: add hour minute in datetime 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');

Tags:

Php Example