Mostly because you are using it incorrectly, you need to use DateTime methods correctly.
In this case, use . Read the manual for more information . Consider this example: ->format()
$myDate = new \DateTime();
echo $myDate->format('Y-m-d H:i:s');
echo $myDate->getTimestamp();
source
share