Single Indexed Array Element To A String (date)

Hello,

New here…

I am stuck on an array issue, that I just cannot seem to figure out. I am looping through an excel document and have broken the three columns out.

The Array that it kicks out, looks like such:
Array (
[0] => 356512090108717
[1] => Production
[2] => DateTime Object ( [date] => 2019-02-20 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/London )
)

I need to convert each of these to a string, but importantly I need [date] to be formatted like such
2019-02-20 instead of 2019-02-20 00:00:00.000000. I cannot figure out how to convert the single element in the array to a string.

Thanks In Advance!

The DateTime object has a format method that can do what you want:

$formatted = $datetime->format('y-m-d');

$formatted will now be your formatted date.

Sponsor our Newsletter | Privacy Policy | Terms of Service