0

From a JSON payload I get a date formatted like so: "2017.03.11". The desired result is: "11 MARCH 2017". I know how to remove the dots and convert the result into what I want using date(). But is there a more direct way to achieve it (without the step removing the dots)?

drake035
  • 3,955
  • 41
  • 119
  • 229

2 Answers2

0

Try this:

$date = DateTime::createFromFormat('Y.m.d', '2017.03.11');

and then with the $date object you can do whatever you need.

user2548436
  • 915
  • 2
  • 16
  • 35
0

This should do what you need.

<?php
$date = "2017.03.11";
$date1 = str_replace(".", "-", $date);
$date1 = strtotime($date1);
$date2 = date('d F Y',$date1);
echo $date2;
?>

2017.03.11    input
11 March 2017 output
dsadnick
  • 624
  • 1
  • 7
  • 25