My issue is that I have array how contain value with dateTime format but I would like modify this value with a format Y-m-d. I tried a lot of thing of issue here but nothing work when I encode my json.
Now I have that :
[contacts] => Array (
[0] => Array (
[createdAt] =>2020-01-29T17:00:04.159+01:00
)
)
And I would result like
[contacts] => Array (
[0] => Array (
[createdAt] =>2020-01-29
)
)
My php code is :
$contacts=$result[contacts];
foreach ($contacts as $contact) {
$time = new DateTime($contact['createdAt']);
$date = $time->format('Y-m-d');
echo '<br>' .$date; //that show the date format I want
}
//that don't show correct format
$json=json_encode($contacts);
print_r($json);
Someone can help me ?