Crashes on:
<?php
$date = "13-06-2015 23:45:52";
echo Datetime::createFromFormat('d-m-Y h:i:s', $date)->format('Y-m-d h:i:s');
?>
PHP Fatal error: Call to a member function format() on boolean
But with other dates works well:
<?php
$date = "10.06.2015 09:25:52";
echo Datetime::createFromFormat('d-m-Y h:i:s', $date)->format('Y-m-d h:i:s');
?>
Wrong format?
Neither example work as you have multiple errors:
Datetime::createFromFormat()
h:i:s
should be H:i:s
.
not a -
Fixes:
<?php
$date = "13-06-2015 23:45:52";
echo DateTime::createFromFormat('d-m-Y H:i:s', $date)->format('Y-m-d h:i:s');
$date = "10.06.2015 09:25:52";
echo DateTime::createFromFormat('d.m.Y H:i:s', $date)->format('Y-m-d h:i:s');
?>