-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?

Muhammad Arif
  • 1,014
  • 3
  • 22
  • 56

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
  • 78,200
  • 7
  • 66
  • 87
0
$start=date('l, d-M-y H:i:s T',strtotime($post['begin']));
Populus
  • 7,470
  • 3
  • 38
  • 54
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
  • 44,654
  • 6
  • 52
  • 63