-1

I' am trying to convert 16/06/2014 8:00 am to 16th June, 2014 8:00 AM

This is the format of the original date.

$date_time = '16/06/2014 8:00 am';

What does that above give me

01st January 1970 12:01 AM

This is the code in place

$date_time = date("dS F Y h:m A", strtotime($date_time )); 
scrowler
  • 24,273
  • 9
  • 60
  • 92
Navneil Naicker
  • 3,586
  • 2
  • 21
  • 31
  • 2
    When `strtotime()` fails you, use [`DateTime::createFromFormat()`](http://us3.php.net/manual/en/datetime.createfromformat.php) Actually, you're better off with `DateTime` much of the time in PHP 5.3+ – Michael Berkowski Mar 06 '14 at 00:43

2 Answers2

1

You can use DateTime::createFromFormat():

$date_time = '16/06/2014 8:00 am';
$date = DateTime::createFromFormat('d/m/Y g:ia', $date_time);

echo $date->format('dS F Y h:m A');

Note: you are using m here, which is a month representation. You should use i instead for the number of minutes:

dS F Y H:i A
scrowler
  • 24,273
  • 9
  • 60
  • 92
1

You just need to change / slashes with - minus

$date_time = '16/06/2014 8:00 am';
$date_time = str_replace('/', '-', $date_time);    
$date_time = date("dS F Y h:i A", strtotime($date_time )); 
                          //here change m with i for minutes, m is for months

echo $date_time;
//output 16th June 2014 08:00 AM

Working sample here

Fabio
  • 23,183
  • 12
  • 55
  • 64