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

编程入门 行业动态 更新时间:2024-10-23 18:33:37
本文介绍了当日期列为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年的日期

本文发布于:2023-10-24 13:48:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524104.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   null   PHP   strtotime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!