If DateTime Object Is Null

前端 未结 2 609

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,

    ".date_format(new DateTime( $search_results_option->HardwareAssetLastUpdateTime ),"d/m/Y H:i")."
    ".$search_results_option->HardwareAssetLastUpdatedByName."
    ".date_format(new DateTime( $search_results_option->HardwareAssetLastDiscoveryScanDate ),"d/m/Y H:i")."";
    

    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

提交回复
热议问题