Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert yyyy-MM-dd HH:mm:ss to "15th Apr 2010" using PHP

Tags:

date

php

format

I have the following date format: 2010-04-15 23:59:59

How would I go about converting this into: 15th Apr 2010

Thanks

like image 611
Keith Donegan Avatar asked Apr 13 '10 12:04

Keith Donegan


2 Answers

echo date("jS M Y",strtotime("2010-04-15 23:59:59"));
like image 99
oezi Avatar answered Oct 29 '22 10:10

oezi


In addition to using date and strtotime, you can do

$dateTime = new DateTime('2010-04-15 23:59:59');
echo $dateTime->format('jS M Y'); // 15th Apr 2010

or

$dateTime = date_create('2010-04-15 23:59:59');
echo date_format($dateTime, 'jS M Y'); // 15th Apr 2010
like image 28
Gordon Avatar answered Oct 29 '22 08:10

Gordon