列稱爲「jdate」被定義爲「VARCHAR(19), 並插入行之前到稱爲表‘fatable’在mysql中,時間戳不是生成日期。爲什麼?
alter table fatable CHANGE jdate jdate TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP;
Then, inserting a row like:
insert into fatable (firstname,lastname, address, city, state, zip, phoneno, emailad, jdate, ddate, cstatus, investam, wamount, comments)
values('john','lee','10 rustling lane','bedford','ny','10506','9142347752','[email protected]', '','09262015','0','100','10','aa');
其結果是:
# id, firstname, lastname, address, city, state, zip, phoneno, emailad, timestamp, ddate, cstatus, investam, wamount, comments
'2015101', 'john', 'lee', '10 rustling lane', 'bedford', 'ny', '10506', '9142347752', '[email protected]', '0000-00-00 00:00:00', '09262015', '0', '100.00', '10.00', 'aa'
列「jdate」具有包含全零的mysql日期格式。沒有顯示當前日期。
您正在插入一個空字符串:'''',嘗試插入:'now()' – alfasin
默認情況下,第一個時間戳列爲零,您將更改'jdate',但嘗試插入一個值在'timestamp'中,你也不是在你的select中查詢那個列... – Aguardientico
另外,如果列允許NULL,mysql爲列使用明確的DEFAULT NULL,嘗試將alter table改爲NOT NULL'而不是'NULL' https://dev.mysql.com/doc/refman/5.0/zh-CN/data-type-defaults.html – Aguardientico