1

Can anyone please help? I have searched many website (including stackoverflow) but can't find my exact answer.

It may be so easy, but I need to know.

2014-11-21 18:49:55

I need to convert it to

6:49 PM, 21th November, 2014

Can anyone help me please?

Thanks in advance for helping.

Pupil
  • 23,834
  • 6
  • 44
  • 66
Abrar Jahin
  • 13,970
  • 24
  • 112
  • 161
  • 1
    What have you done so far yourself? A simple use of `strtotime()` and `date()` should fix this for you. A more elegant way is using `DateTime` – RichardBernards Dec 02 '14 at 12:18

4 Answers4

1

Try this-

$date = "2014-11-21 18:49:55";
echo date('g:i A, jS F, Y', strtotime($date));

Output -

6:49 PM, 21st November, 2014
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
1

This should work for you:

$date = "2014-11-21 18:49:55";
echo date('g:i A, dS F Y', strtotime($date));

Output:

6:49 PM, 21st November 2014
Rizier123
  • 58,877
  • 16
  • 101
  • 156
0
<?php
$providedTime = '2014-11-21 18:49:55';
$newTime = strtotime($providedTime);
echo date('g:i A, dS F Y', $newTime);
?>

[Working example][1]

We can use PHP's date() function to get the provided date in required format.

the date() function has various parameters and we can use nice use of them.

Hope it works for you.

Pupil
  • 23,834
  • 6
  • 44
  • 66
0
$originalDate = "2014-11-21 18:49:55";
$newDate1 = date("g:i A,", strtotime($originalDate));
$newDate2 = date("d", strtotime($originalDate));
$newDate3 = date("F, Y", strtotime($originalDate));
echo $newDate1.' '.$newDate2.'th '.$newDate3;
Michael
  • 425
  • 3
  • 13