从php [重复]解析存储在mysql DATETIME中的日期

This question already has an answer here:

I've got a date in DD.MM.YYYY h:mm a format, how could i parse it in php or laravel to store it in a datetime field in mysql database?

Here's the date i want to parse: 29.08.2015 11:00 pm

I tried to parse to parse it like this:

date_create_from_format('DD.MM.YYYY h:mm a','29.08.2015 11:00 pm');

But it didn't work, it returns false...

</div>
$date = date_create_from_format('j.m.Y h:i a','29.08.2015 11:00 pm');
echo $date->format('Y-m-j H:i:s');

Outputs 2015-08-29 23:00:00

new DateTime(string date) converts a string to a date object without caring the format. You can pass '29-8-2015','29 Aug 2015'.. etc as $datestring. No need to define the format of input.

$datestring='29.08.2015 11:00 pm';      //defined date as string
$datetime = new DateTime($datestring);      //create datetime of defined date
$datetime = $datetime->format('Y-m-d H:i:s');   //reformat to the format we need