-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,228
  • 4
  • 23
  • 41

2 Answers2

3

Just try with:

$input  = '201501';
$output = DateTime::createFromFormat('Ym', $input)->format('F Y');
hsz
  • 143,040
  • 58
  • 252
  • 308
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