当日期列为null时,PHP strtotime返回1970年的日期 [英] PHP strtotime returns a 1970 date when date column is null

查看:392
本文介绍了当日期列为null时,PHP strtotime返回1970年的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to display $row->depositdate in dd-mm-yyyy format.

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

If the date column in database is null the date displayed is : 01-01-1970

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

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

If the date is null in database it should display nothing , otherwise the date in dd-mm-yyyy format should be displayed.

预先感谢

Sandeep

推荐答案

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

NULL is interpreted as 0 by strtotime, since it want to be passed an integer timestamp. A timestamp of 0 means 1-1-1970.

因此,您必须检查自己是否为$row->depositdate === NULL,如果是,则根本不要调用strtotime.

So you'll have to check for yourself if $row->depositdate === NULL, and if so, don't call strtotime at all.

这篇关于当日期列为null时,PHP strtotime返回1970年的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆