Björn Schönrock Björn Schönrock - 1 year ago 114
PHP Question

PHP - How to get datetime string from DateTime object

I've made a DateTime object using

$currtime = DateTime::createFromFormat("YmdHi");

Is there a way to get a string or an integer, which contains, for example,

$currtime->modify("+2 hours");
$newtime = $currtime->format("YmdHi");


$newtime = 2147483647

Answer Source

This will help you

$current_date_object= new DateTime();
$current_date_object->modify("+2 hours");
$current_date_string= $current_date_object->format("Y-m-d H:i:sO");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download