When I try to output a DateTime object, it is literally printing the format, e.g.
Y-m-d H:i:s
Code
$db = new PDO('mysql:host=localhost;dbname=xxx;charset=utf8', 'xxx', 'xxx');
$dbTime = new DateTime(current($db->query('SELECT NOW()')->fetchAll(PDO::FETCH_COLUMN, 0)));
$myTime = new DateTime();
$diff = $myTime->diff($dbTime);
echo $diff->format('Y-m-d H:i:s');
From reading other questions and examples this should work so I’m confused why it’s not.
The
DateTime::diffmethod returns aDateIntervalobject. Your getting unexpected results because you are calling format on aDateIntervalobject which is different to the implementation on theDateTimeobject. see http://php.net/manual/en/dateinterval.format.php for more info on how to use it.