如何防止PHP将具有0000-00-00值的DateTime对象转换为-0001-11-30 [英] How to prevent PHP to convert a DateTime object with 0000-00-00 value to -0001-11-30

查看:80
本文介绍了如何防止PHP将具有0000-00-00值的DateTime对象转换为-0001-11-30的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在使用Doctrine 2和MySQL。当我在mysql中使用datetime字段分别在PHP中使用DateTime时遇到一些问题。在我的数据库中,日期值为0000-00-00,在PHP中,该值将转换为-0001-11-30。我很高兴,所以我需要检查0000-00-00的日期值。有人有一些想法来帮助吗?谢谢。



N.B。我正在考虑是否对-0001-11-30而不是0000-00-00进行检查。

解决方案

如果未设置日期,则使用 NULL 来表示该状态。这解决了您的问题,并使数据库模式更加清晰和详细。


Currently i'm working with Doctrine 2 and MySQL. I encounter some problems when I work with datetime fields in mysql respectively DateTime in PHP. When in my database the date value is "0000-00-00", in PHP this value is converted to -0001-11-30. I'm note pleased about that, so I need to make a check for "0000-00-00" value of date. Does anybody have some idea on this to help? Thanks.

N.B. I'm thinking if it is right to make checking on "-0001-11-30" instead of "0000-00-00".

解决方案

If the date is not set use NULL to indicate that state. That solves your problem and makes database schema much more clear and verbose.

这篇关于如何防止PHP将具有0000-00-00值的DateTime对象转换为-0001-11-30的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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