The variable time_of_last_update in the database is of type datetime, and all I want to do is really print it out in the table (below) but ideally I would like to know for future reference how to cast it/convert it to a DateTime type in PHP, to then use the methods on it such as ->format etc. Doing:
$time_date = $row['time_of_last_update'];
$time_date->format('Y-m-d H:i:s');
Seems obvious to me coming from C#, but I get "Call to a member function format() on a non-object", and casting doesn't seem to hep me either. This seems really simple/common, but I cannot find any examples.
$describeQuery = 'SELECT username, firstname, surname, location, time_of_last_update FROM location';
$query = sqlsrv_query($link, $describeQuery);
echo '<table>';
echo '<tr><th>Username</th><th>Firstname</th><th>Surname</th><th>Location</th><th>Time of last Update</th></tr>';
while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC))
{
// WANT TO CONVERT time_of_last_update (SQL datetime) to a PHP DateTime variable??
echo '<tr>';
echo '<td>' . $row['username'] . '</td>';
echo '<td>' . $row['firstname'] . '</td>';
echo '<td>' . $row['surname'] . '</td>';
echo '<td>' . $row['location'] . '</td>';
echo '<td>' . $row['time_of_last_update'] . '</td>';// RETURNING ERROR "Object of class DateTime could not be converted to string"
}
echo '</table>';
sqlsrv_free_stmt($query);
sqlsrv_close($link);
Thanks
var_dump($row['time_of_last_update']);output?