cebo
cebo

Reputation: 818

DateTime::createFromFormat(): Call to a member function format() on bool

I understand that the issue is in my format string, I'm just having a little trouble figuring out exactly what it should look like.

I am using a form which is sent directly to my php script via the action="" (instead of via javascript in onsubmit). I am using a date input which ends up formatting the date like the following random example:

2020-09-15T15:07

My php with the format looks like this:

$date = DateTime::createFromFormat("Y-m-d*H-i", $_POST["registrationDeadline"]);
echo "<h1>" . $date->format("Y-m-d") . "</h1>";

I assume the issue is something to do with the letter T in the date, I assumed that * would allow me to skip over that. I have also tried "Y-m-dTH-i" but I don't think I'm actually supposed to use the T there since that is a reserved formatting character.

Upvotes: 0

Views: 2752

Answers (1)

Prince Dorcis
Prince Dorcis

Reputation: 1045

There is colon between the hour and the minutes, instead of hyphen:

$date = DateTime::createFromFormat("Y-m-d*H:i", $_POST["registrationDeadline"]);

Upvotes: 2

Related Questions