mysql 日期类型 字段 设值为空,如何在mysql日期类型字段中插入空值?

How to insert a NULL or empty value in a mysql date type field (NULL = yes).

If I try to insert an empty value it inserts 0000-00-00 but I want to keep it empty or NULL.

Thanks for help.

UPDATE

Please see that I have set default value as NULL

`payment_due_on` date DEFAULT NULL,

Ok OKies

I have got it working now

function get_mysqlDate($date, $delimiter='/') {

if(check_empty($date)) {

return 'NULL';

}

list($d, $m, $y) = explode($delimiter, $date);

//$datetime = strtotime($date);

return "'".date('Y-m-d', mktime(0,0,0,$m, $d, $y))."'";

}

"... SET mydate = ".get_mysqldate($_POST['mydate'])." ...."

Cheers

解决方案

If that's happening, it's because the column has been defined with NOT NULL or with a default '0000-00-00'. You need to change the column definition to allow NULLs and have no default.

Your insert should be specifying NULL, as well, not '', if that's what you mean by "empty value".

  • 0
    点赞
  • 0
    收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:深蓝海洋 设计师:CSDN官方博客 返回首页
评论
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值