I am returning some search results after form submit. All is working fine, until I get to a field that is SMALLDATETIME and allows NULL. At least one of the returned rows has the field as NULL. As you can see in the code below, when it is not NULL I am converting it from Date to String no problem, but i get an error Message for the rows with NULL.
Any ideas?
Code:
$search_results = sqlsrv_query($database_connection, $search_results_sql, array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
if($search_results){
$returned_rows = sqlsrv_has_rows($search_results);
if($returned_rows === true){
getAssetSearchData($search_results);
}
}
function getAssetSearchData($search_results){
while($search_results_option = sqlsrv_fetch_object($search_results)){
echo "
<tr>
<td class='col45'>".date_format($search_results_option->HardwareAssetLastUpdateTime,"d/m/Y H:i")."</td>
<td class='col46'>".$search_results_option->HardwareAssetLastUpdatedByName."</td>
<td class='col47'>".date_format($search_results_option->HardwareAssetLastDiscoveryScanDate,"d/m/Y H:i")."</td></tr>";
}
}
Error Message:
Warning: date_format() expects parameter 1 to be DateTimeInterface, null given in