-2

I am trying to convert a date '2019-04-18' to something like this '18 Apr 2019' in php.

$date=date_create("2019-04-18");
echo date_format($date,'jS F Y');

It is giving me output like this :

18th April 2019

But i need output to be '18 Apr 2019' ie: 3 letters of month

Snehal
  • 137
  • 1
  • 4
  • 16

4 Answers4

1

You need to use M here for month and d for day:

$date=date_create("2019-04-18");
echo date_format($date,'d M Y'); // 18 Apr 2019

According to PHP Manual:

d => Day of the month, 2 digits with leading zeros (e.g 01 to 31)

M => A short textual representation of a month, three letters (e.g Jan through Dec)

devpro
  • 16,184
  • 3
  • 27
  • 38
0

You just need to tune date formatting like below,

echo date_format($date,'d M Y');

for more details or the link from where I created this format is here.

Rahul
  • 18,271
  • 7
  • 41
  • 60
0

Instead of F and jS you need to use d and M

echo date_format($date,'d M Y'); 

The above script will print following output

// 18 Apr 2019
Ayaz Ali Shah
  • 3,453
  • 9
  • 36
  • 68
0
<?php 

$date=date_create("2019-04-18");
echo date_format($date,'jS M Y');

echo "<br>";
echo date_format($date,'j M Y');
Kelvin KCS
  • 76
  • 3
  • 6
    While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. A ***good answer*** will always have an explanation of what was done and why it was done in such a manner, not only for the OP but for future visitors to SO. – Jay Blanchard Apr 18 '19 at 11:22