-3

I have a date value that is being passed as 201501.

How could I take that and display January 2015 instead?

It's being passed through a PHP variable.

Philip
  • 2,460
  • 4
  • 27
  • 52

2 Answers2

3

Just try with:

$input  = '201501';
$output = DateTime::createFromFormat('Ym', $input)->format('F Y');
hsz
  • 148,279
  • 62
  • 259
  • 315
0

Try below code

$data = '201501';

$monthNum = substr($data,4);
$year = substr($data,0,4);

$dateObj   = DateTime::createFromFormat('!m', $monthNum);

$monthName = $dateObj->format('F'); 

echo $monthName.' '.$year;
Lalit Sharma
  • 555
  • 3
  • 12