1

I have a problem getting the year and month from the date given. I have this date 201911.. when i use

date('F Y',strtotime(201911)).. 

it shows Oct-19. It should be Nov-19

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Rhea Lorraine
  • 67
  • 1
  • 7
  • strtotime doesn't know if the 11 is the day or month, just add 01 to the end of it. `date('F Y', strtotime('20191101'))` – Alex Barker Oct 28 '19 at 23:38

3 Answers3

1

You would do better to use date_create_from_format:

$date = date_create_from_format('Ym', 201911);
echo $date->format('F Y');

Output:

November 2019

Demo on 3v4l.org

Nick
  • 138,499
  • 22
  • 57
  • 95
0

You are almost there. Just put ' around your String

echo date('F Y',strtotime('2019-11'));

Echo: November 2019

davidev
  • 7,694
  • 5
  • 21
  • 56
0

All of another responses are ok!. the problem is that you dont tell to php what is the format of the date that you need trasform.

DateTime::createFromFormat('Ym', 201911)->format('F Y');
Manuel Panizzo
  • 876
  • 3
  • 8