Reputation: 11
$date = $feed[$x]['date']; // Date string = 04-29-2013
$time = $feed[$x]['time']; // Time string = 11:30pm
I need to add 2 hours to the time but date also has to be correct.
How do I add 2 hours to this string or what ever x hours I need to add to it.
Upvotes: 1
Views: 38
Reputation: 254886
$date = '04-29-2013';
$time = '11:30pm';
$compound = $date . ' ' . $time;
$dt = DateTime::createFromFormat('m-d-Y h:ia', $compound);
$dt->modify('+2 hour');
$newDate = $dt->format('m-d-Y');
$newTime = $dt->format('h:ia');
var_dump($newDate, $newTime);
Online demo: http://ideone.com/x4WgDV
Upvotes: 4