If I go on my wordpress site
<?php $theCurrentDate = new DateTime(); ?>
<?php echo $theCurrentDate; ?>
It causes a critical error on my website, why?
PHP DateTime exception and errors handling
<?php
try {
$dt = new DateTime();
echo $dt;
} catch (Exception $e) {
var_dump($e->getMessage());
}
?>
I still get critical error on site.
What is going on here? Howcome when you echo datetime() in php it breaks wordpress?
CodePudding user response:
https://www.php.net/manual/en/datetime.format.php
Apparently you have to specify format
<?php $theCurrentDate = new DateTime(); ?>
<?php echo $theCurrentDate->format('Y-m-d H:i:s'); ?>