我想以 dd-mm-yyyy 格式显示 $row->depositdate。
如果数据库中的日期列为空,则显示的日期为:01-01-1970
echo "<td align=center>".date('d-m-Y', strtotime($row->depositdate))."</td>";
如果数据库中的日期为空,则不应显示任何内容,否则应显示 dd-mm-yyyy 格式的日期。
提前致谢
桑迪普
最佳答案
NULL 被 strtotime 解释为 0,因为它想要传递一个整数时间戳。时间戳 0 表示 1-1-1970。
因此,您必须自己检查是否 $row->depositdate === NULL
,如果是,则根本不要调用 strtotime。
关于当日期列为空时,PHP strtotime 返回 1970 年日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7737363/