Frage

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

War es hilfreich?

Lösung

You can try like this,

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

Andere Tipps

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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top