0

When looking over my code for a bug, I realized that while the timestamp I was passing from the JQuery-UI-Picker was in the format of 10/06/2015 16:08, my MYSQL Insert statement was using FROM_UNIXTIME and converting it to all 0's. To fix this, I need to convert this time to the format 00-00-0000 00:00:00.

I found the date_create_from_format function I had not seen before, however when using it I am getting a False return. As I believe I am using it properly, can anyone please help in pointing out what the problem is?

$dt = "10/06/2015 16:08";
$res = date_create_from_format('m/d/y h:i', $dt);

1 Answers1

1

you need to call $res->format, i.e.:

$dt = '10/06/2015 16:08';
$res = DateTime::createFromFormat('d/m/Y H:i', $dt);
echo $res->format('Y-m-d H:i:s')
//2015-06-10 16:08:00

Learn more about php date and time

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268