-5

I have a date that gets sent from a database which comes in a string format of '2018-01-01'. What I want to do is convert it into a string of month and year. E.G. 'January 2018'.

What would be the best way of doing so using PHP?

thatemployee
  • 473
  • 1
  • 6
  • 12

1 Answers1

2

Try using the strtotime function to turn your string into a timestamp and the date function with the F Y format to get what you want:

$date = "2018-01-01";
$formatted = date("F Y", strtotime($date));
Angel Politis
  • 10,955
  • 14
  • 48
  • 66