Reputation: 614
I'm decoding a JSON response and outputting it in a simple table. Here is a sample of the code:
<?php
foreach($results['Events'] as $values)
{
echo '<tr><td>' . $values['Title'] . '</td>';
echo '<td>' . $values['Details']['Venue'] . '</td>';
echo '<td>Event date:' . $values['Details']['Date'] . '</td></tr>';
}
?>
Since Date
has a timezone added to it, this is what I get:
Event title | Event venue | Event date
Event one | Venue one | 2016-01-01T00:00:00
Event two | Venue two | 2016-01-02T00:00:00
Event three | Venue three | 2016-01-03T00:00:00
Is there a way to remove "T00:00:00" when echoing the results? This is a desired outcome:
Event title | Event venue | Event date
Event one | Venue one | 2016-01-01
Event two | Venue two | 2016-01-02
Event three | Venue three | 2016-01-03
Upvotes: 1
Views: 156
Reputation: 11987
you can also use strtotime()
echo '<td>Event date:' . date("Y-m-d",strtotime($values['Details']['Date'])) . '</td></tr>';
Upvotes: 3
Reputation: 793
Use DateTime:
$date = new \DateTime($values['Details']['Date']);
echo '<td>Event date:' . $date->format('Y-m-d') . '</td></tr>';
Upvotes: 5