How do I convert this date 2014-05-09 00:00:00
into 2014-may-09
in PHP ??
Asked
Active
Viewed 2,523 times
1

Ajey
- 7,924
- 12
- 62
- 86
-
Some simple google search would ve solved it.i think. date('Y-M-d',strtotime('2014-05-09 00:00:00')); http://www.php.net/manual/en/book.datetime.php – Nabin Kunwar May 15 '14 at 05:27
-
1For mysql [demo](http://www.sqlfiddle.com/#!2/d41d8/37441) – M Khalid Junaid May 15 '14 at 05:27
-
`date("Y-M-d",strtotime("2014-05-09 00:00:00"));` refer [this](http://php.net/manual/en/function.date.php) for different format characters. – shyammakwana.me May 15 '14 at 05:36
-
1@NabinKunwar i just spent 2 hours on a 'simple google search'. This is the first page that gives me a REAL USABLE answer. Not everyone is a pro programmer... – james walker Dec 04 '16 at 20:28
-
@jameswalker It's not about being pro programmer, Its just about learning to search right. Anyway glad you found solution – Nabin Kunwar Dec 05 '16 at 09:40
4 Answers
7
Using PHP
Use the DateTime
class:
$d = new DateTime('2014-05-09 00:00:00');
echo $d->format('Y-M-d');
This will produce 2014-May-09
. If you need the month to be in lowercase, run the string through strtolower()
or mb_strtolower()
.
Using MySQL
Alternatively, format the date in the query so that it returns the desired format. Use the MySQL DATE_FORMAT()
function for this. The format you are looking for is %Y-%b-$d
.

rink.attendant.6
- 44,500
- 61
- 101
- 156
1
You can try some thing like this
$data="2014-05-09 00:00:00";
$datetime = strtotime( $data);
$formatedDate = date("Y-M-d", $datetime);
I hope this what you are asking for!
Happy Coding!

Deepak Goswami
- 2,030
- 1
- 16
- 22
0
try date()
$d = '2014-05-09 00:00:00';
echo date('Y-M-d', strtotime($d)); //2014-May-09

Rakesh Sharma
- 13,680
- 5
- 37
- 44