php - Reformatting a result from a json file ← (PHP)

I have a json file I am getting returned from an API. I have learnt how to format it and lay it out in PHP but one bit I can't work out is how to reformat the date that is returned.

This is the page that displays the results:

<body>

    <h1 align="center"><font face ="Arial"><u><br>Results<br><br></u>Postcode - <?php echo $resultData['postcode']; ?></font></h1>
    <br>
    <br>
    <h2 align="center">Known Floor Sizes Listed By Report Date</h2>
    <br>
    <table class= "general" align= "center" bgcolor="#ffffff">
        <tr>
            <td align="center" rowspan="2"><b>Inspection Date</b></td>
            <td align="center" rowspan="2"><b>Address</b></td>
            <td align="center" colspan="2"><b>Size in</b></td>
            </tr>
            <tr>
                <td align="center"><b>SqM</b></td>
                <td align="center"><b>SqFt</b></td>
                </tr>
        <?php foreach ($resultData['known_floor_areas'] as $property) { ?>
            <tr>
                <td align="center"><?php echo $property['inspection_date']; ?></td>
                <td align= "left" ><?php echo $property['address']; ?></td>
                <td align="center"><?php echo (round($property['square_feet'] * 0.092903,0));?></td>
                <td align="center"><?php echo $property['square_feet']; ?></td>
            </tr>
        <?php } ?>
    </table>
    
</body>

This displays the date in the format: 2015-06-22T23:00:00.000000Z

I want to change the format to a basic: 2015-06-22

I'm sure it's simple but after a lot of searching I'm going round in circles.

Answer



Solution:

Use DateTime() then format() it:

<td align="center"><?php echo (new DateTime($property['inspection_date']))->format('Y-m-d'); ?></td>

Source