I've used DateTime::createFromFormat() to parse string into date before, but today I found a problem and I get null from this call.
echo $date_string;
$test = DateTime::createFromFormat('M d Y, H:i:s T', trim($date_string));
echo $test->format('Y-m-d H:i:s');
Output:
Oct 16 2013, 15:45:02 CEST
( ! ) Fatal error: Call to a member function format() on a non-object in (...) on line 51
Where line 51 is the last line where I call format().
So, am I missing something? Thanks in advance!
The output of DateTime::getLastErrors() as requested:
(
[warning_count] => 0
[warnings] => Array
(
)
[error_count] => 4
[errors] => Array
(
[3] => Unexpected data found.
[11] => Unexpected data found.
[22] => Unexpected data found.
[36] => The timezone could not be found in the database
)
)
The catch, requested by @whizzzkid:
DateTime::__construct(): Failed to parse time string (Oct 16 2013, 10:00:00 CEST) at position 3 (&): Unexpected character
$date_string.$testhas becomefalseon failure.CEST.2013-10-16 15:45:02. Don't see a problem.