-1

I have date like "2014-05-14 19:15:00" but i want to convert it in "7:15 PM 14th May 2014".

Here is my code:

$start = $post['begin'];
$start='2014-05-14 19:15:00';
$start = date('l, d-M-y H:i:s T',$post['begin']);

but not worked for me. How i get the desired date?

Arsal Ali
  • 978
  • 3
  • 20
  • 54

3 Answers3

2

The format is wrong and you need a timestamp for date(). To get the format 7:15 PM 14th May 2014 you will need to convert the datetime string to a timestamp and then format it correctly:

$start = date('g:i A jS F Y', strtotime($post['begin']));
AbraCadaver
  • 77,023
  • 7
  • 60
  • 83
0
$start=date('l, d-M-y H:i:s T',strtotime($post['begin']));
Populus
  • 7,136
  • 3
  • 37
  • 51
0

Use DateTime class for date operations

$start='2014-05-14 19:15:00' ;
$date = DateTime::createFromFormat('Y-m-d H:i:s', $start);
echo $date->format('l, d-M-y H:i:s T') ;
Abhik Chakraborty
  • 43,914
  • 5
  • 48
  • 61