If DateTime Object Is Null

前端 未结 2 608

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 ha

相关标签:
2条回答
  • 2020-12-12 05:54

    Try this,

    <td class='col45'>".date_format(new DateTime( $search_results_option->HardwareAssetLastUpdateTime ),"d/m/Y H:i")."</td>
    <td class='col46'>".$search_results_option->HardwareAssetLastUpdatedByName."</td>
    <td class='col47'>".date_format(new DateTime( $search_results_option->HardwareAssetLastDiscoveryScanDate ),"d/m/Y H:i")."</td></tr>";
    

    date_format() need the date to be in DateTime format when supplied, you are passing a string.

    The other thing may be that $search_results_option is empty

    For NULL values:

    ( $search_results_option->HardwareAssetLastDiscoveryScanDate != null ? date_format(new DateTime( $search_results_option->HardwareAssetLastDiscoveryScanDate ),"d/m/Y H:i") : '' )

    This will check for a null value, if it is not null it will display the formatted datetime, els eit will display nothing

    0 讨论(0)
  • 2020-12-12 06:04
    <td>".(
       is_null($search_results_option->HardwareAssetLastDiscoveryScanDate) ? '' : 
           date_format($search_results_option->HardwareAssetLastDiscoveryScanDate,
            "d/m/Y H:i")
        )
     ."</td>";
    
    0 讨论(0)
提交回复
热议问题