I'm trying to fill a HTML table with the different values of a table in SQL Server working with PHP. This is the code.
...
while($datosPerfil = sqlsrv_fetch_array($resultado)){
echo "<tr>";
echo "<td>";
echo $datosPerfil['CPR_Name'];
echo "</td>";
echo "<td>";
echo $datosPerfil['CON_SC_Id'];
echo "</td>";
echo "<td>";
echo $datosPerfil['CON_Tel_Number'];
echo "</td>";
echo "<td>";
echo $datosPerfil['CON_Startup_Date'];
echo "</td>";
echo "</tr>";
}
....
The field "CON_Startup_Date" is date type and allow nulls. And this is the error that appears:
Catchable fatal error: Object of class DateTime could not be converted to string
And when I write:
echo $datosPerfil['CON_Startup_Date']->format("Y-m-d");
It works but when arrives to a null value shows an error:
Fatal error: Call to a member function format() on null
Any solution that allows to run the echo for null values and correctly in date type?
