0

So, i have this format date :

2014-16-02 08:00:00 PM

YYYY-DD-MM HH:MM:SS AM/PM Format

Years - Days - Months 

What is the best way to convert this to

2014-02-16 20:00:00

Without the AM/PM and with the month before the days.

I already tried it with the DateTime function from PHP :

//    $date = new \DateTime($row[0]);
//    $date_formatted = $date->format('Y-m-d H:i:s');

But this is not working because Datetime recognises the days as months because of this format YYYY-DD-MM

How to do this in PHP

Thomas Crawford
  • 886
  • 2
  • 15
  • 45

1 Answers1

1

Try this:

$date = DateTime::createFromFormat('Y-d-m H:i:s A', '2014-16-02 08:00:00 PM');
echo $date->format('Y-m-d H:i:s'); // Gives 2014-02-16 20:00:00
Rizier123
  • 58,877
  • 16
  • 101
  • 156
Indrasis Datta
  • 8,692
  • 2
  • 14
  • 32