编程语言
首页 > 编程语言> > PHP strtotime返回1970日期,当date列为null时

PHP strtotime返回1970日期,当date列为null时

作者:互联网

我想以dd-mm-yyyy格式显示$row-> depositdate.

如果数据库中的日期列为空,则显示的日期为:01-01-1970

echo "<td align=center>".date('d-m-Y', strtotime($row->depositdate))."</td>";

如果数据库中的日期为空,则不显示任何内容,否则应显示dd-mm-yyyy格式的日期.

提前致谢

桑迪普

解决方法:

由strtotime将NULL解释为0,因为它希望传递整数时间戳.时间戳0表示1-1-1970.

所以你必须自己检查$row-> depositdate === NULL,如果是这样的话,根本不要调用strtotime.

标签:strtotime,php,date-format
来源: https://codeday.me/bug/20190928/1829514.html