0

I am saving date and time in a single column i.e 2015-04-15 13:22:58 and I want to show this time and date in this format: 15th April 2015, 1:22 pm. I have used this code:

$dt = '2015-04-15 13:22:58';
echo date("jS F Y", strtotime($dt)); 

and it shows only date (15th April 2015). How can I fetch time along with date?? Any help would be highly appreciable.

Haris Khan
  • 335
  • 5
  • 20
  • Possible duplicate of [Convert one date format into another in PHP](https://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php) – Elementary Aug 30 '18 at 06:39

3 Answers3

1

change "jS F Y" to "js F Y g:i a". That will output the time in your desired format as well as the date.

$dt = '2015-04-15 13:22:58';
echo date("jS F Y g:i a", strtotime($dt));

Output:

15th April 2015 1:22 pm
Nick
  • 138,499
  • 22
  • 57
  • 95
1

Try

$dt = '2015-04-15 13:22:58';

echo date("jS F Y h:i a", strtotime($dt)); 
//Result is 15th April 2015 01:22 pm

echo date("jS F Y g:i a", strtotime($dt)); 
// Result is 15th April 2015 1:22 pm
0

if you want to format date time in php, you can use date_format like this.

echo date_format(strtotime($dt), "jS F Y g:i A");