如何在mysql日期类型字段中插入空值? [英] how to insert an empty value in mysql date type field?
问题描述
如何在mysql日期类型字段中插入NULL或空值(NULL = yes)。
How to insert a NULL or empty value in a mysql date type field (NULL = yes).
如果我尝试插入一个空值,它将插入0000- 00-00,但是我想保持为空或为空。
If I try to insert an empty value it inserts 0000-00-00 but I want to keep it empty or NULL.
感谢您的帮助。
更新
请注意,我已将默认值设置为NULL
Please see that I have set default value as NULL
`payment_due_on` date DEFAULT NULL,
Ok OKies
我现在正在工作
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'])." ...."
干杯
推荐答案
如果发生这种情况,那是因为列已经被定义为 NOT NULL
或使用默认'0000-00-00'
。您需要更改列定义以允许 NULL
s,并且没有默认值。
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 NULL
s and have no default.
您的插入应该指定NULL ,而不是''
,如果这是你的意思是空值。
Your insert should be specifying NULL, as well, not ''
, if that's what you mean by "empty value".
这篇关于如何在mysql日期类型字段中插入空值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!