in php how do I add a hour to

$newdatetime = $olddatetime(strtotime("+1 hour"));
// this is the format of $olddatetime 0000-00-00 00:00:00 

I already have the hour difference in the timezones I know its with the strtotime function but I couldn't get it formatted right to work

有帮助吗?

解决方案

You can try like this,

date( "Y-m-d H:i:s", (strtotime($olddatetime." +1 hour")));

其他提示

Try using DateTime objects:

$newdatetime = new DateTime($olddatetime);
$newdatetime->modify('+1 hour');

echo $newdatetime->format('Y-m-d H:i:s'); // or whatever output format you want

Try to use following code,

    $olddatetime = "2014-03-07 10:00:00"; // Requested format
    $newdatetime = (strtotime($olddatetime."+1 hour")); // add one hour
    $newdatetime = date("Y-m-d H:i:s", $newdatetime); // New date time
    echo $newdatetime;exit; // Print it
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top