quicksnack86 quicksnack86 - 1 year ago 70
PHP Question

How to convert date time to timestamp, add 6 hours and convert it back to date time in PHP?

how to add 6 hours to this string?

$parent = "2011-08-04 15:00:01";

I think the best way is to convert it to timestamp add 21600 seconds and then convert it back to date time.

How to do this?

Thanks in advance.

Answer Source

You're maybe looking for the http://www.php.net/manual/en/function.strtotime.php function

$timestamp = strtotime("2011-08-04 15:00:01");
$timestamp += 6 * 3600;
echo date('Y-m-d H:i:s', $timestamp);