gpt4 book ai didi

php - 使用 strtotime() 和 date() 更改日期时间格式时导致特定日期时间的空值

转载 作者:行者123 更新时间:2023-11-29 13:38:03 24 4
gpt4 key购买 nike

我使用此代码将此“29-08-2013 12:27:04”日期时间转换为此格式“2013-08-29 12:27:04”

$insert_dts = date('Y-m-d H:i:s',strtotime($this->input->post('insert_dts')));

但问题是;每当该值变为 null 时,都会生成“1970-01-01 00:00:00”。

由于我使用 $insert_dts 进入数据库,因此它输入的是这个值(1970-01-01 00:00:00)而不是“0000-00-00 00:00” :00' 在 mysql 数据库的日期时间字段中。

我知道这可以通过 if else 检查 $this->input->post('insert_dts') 是否为 null 来解决。

在不逐一检查的情况下是否还有其他解决方案?

最佳答案

使用触发器BEFORE INSERT可能是一种更简洁的方法。

http://dev.mysql.com/doc/refman/5.0/fr/create-trigger.html

不确定您是否认为它与“检查每个”不同。

关于php - 使用 strtotime() 和 date() 更改日期时间格式时导致特定日期时间的空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18504494/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com