Viewed   108 times

Crashes on:

    $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:

    $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:

  1. You forgot your second parameter to Datetime::createFromFormat()
  2. h:i:s should be H:i:s
  3. Your date in the second example is separated by a . not a -


    $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');
Sunday, December 25, 2022

convert it to a PHP date object with strtotime() then output it with date()


Some more detail; try:

$time = strtotime('Tue Jan 05 11:08:27 +0000 2010');
echo date("Y-m-d h:i", $time);

Y = 4 digit year m = 2 digit month (with leading 0) d = 2 digit month (with leading 0)

h = 12 hour time (leading 0) i = minutes (with leading 0) for all the formatting options

Tuesday, August 2, 2022

You need to convert it to something you can use for further formatting. strtotime() is a good start, which yields a unix timestamp. You can format that one using strftime() then.

strftime("%d-%b-%G", strtotime($ts));
Tuesday, November 1, 2022

The answer was due to hidden characters located in the lessons.db file.

The error shown had nothing to do with this and I would like to thank everyone who took the time to give their two pence.

Wednesday, November 23, 2022

As I stated in comments, you didn't choose a database.

As requested:

This line:

$db = new mysqli("localhost","root","");

Should have read as:

$db = new mysqli("localhost","root","", "database");

and replacing "database" with the name of your database.

The documentation can be found at the following address on


Example pulled from the manual along with error checking:

$link = mysqli_connect("", "my_user", "my_password", "my_db");

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;

echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;


Note: Alhough you can still theoretically connect, you just wouldn't be able to query anything though. That's where error checking is important during development testing.

Friday, August 26, 2022

No, there is nothing built-in for Dateobjects, but there are a bunch of libraries to deal with and format them:

  • date.js
  • moment.js
  • XDate
  • Date and Date.Extras in Mootools
  • Date in Sugar
  • a few functions in Mochikit
  • DateFormat (only PHP's date)
  • date at php.js
  • DataType in YUI, especially for i18n
  • date-functions.js, used especially by JQuery datetimepicker plugin
Thursday, August 18, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :