1

I am currently facing an issue with date_create_from_format PHP. Here is the code:

date_default_timezone_set('Asia/Kathmandu');
$date = date_create_from_format('d/m/Y H:iA', '28/05/2016 15:24PM');
echo date('d/m/Y h:iA',$date->getTimestamp());
//returns 29/05/2016 03:24AM

I am just trying to change the 24 hour time to 12 hour. But now working.Thanks.

BulletProof47
  • 54
  • 1
  • 10

1 Answers1

0

You must create date from one type. Use PM-AM OR 24h format. Otherwise it will be 15:43 PM = 12:43 PM + 3 hour.

Try like this:

$date = date_create_from_format('d/m/Y H:i', '28/05/2016 15:24');

UPDATE

If you do not control the input data, you can use a crutch:

$date = date_create_from_format('d/m/Y H:i', substr('28/05/2016 15:24PM', 0, -2));
Maxim Tkach
  • 1,607
  • 12
  • 23