San*_*505 12 php strtotime date-format
我想以dd-mm-yyyy格式显示$ row-> depositdate.
如果数据库中的日期列为空,则显示的日期为:01-01-1970
echo "<td align=center>".date('d-m-Y', strtotime($row->depositdate))."</td>";
Run Code Online (Sandbox Code Playgroud)
如果数据库中的日期为空,则不显示任何内容,否则应显示dd-mm-yyyy格式的日期.
提前致谢
桑迪普
Gol*_*rol 19
由strtotime将NULL解释为0,因为它希望传递整数时间戳.时间戳0表示1-1-1970.
所以你必须自己检查一下$row->depositdate === NULL,如果是的话,根本不要打电话给strtotime.
NULL 转换为0 - 时代(1-1-1970)
这样做
echo "<td align=center>".($row->depositdate ? date('d-m-Y', strtotime($row->depositdate)) : '')."</td>";
Run Code Online (Sandbox Code Playgroud)