在datetime数据类型中插入NOW()值将返回0000-00-00 00:00:00 [英] Inserting NOW() value in datetime datatype is returning 0000-00-00 00:00:00
问题描述
我有一个数据库,该数据库具有完美运行的NOW()函数,可以显示正确的日期. 在意外删除它之后,我创建了一个类似的数据库,但是当我插入NOW()进行插入时 当前当前日期,它将插入为0000-00-00 00:00:00.
I had a database that had a perfectly working NOW() function, displaying the right date. And after accidentally deleted it, I created a similar database, but when I inserted NOW() to insert current the current date, it would insert as 0000-00-00 00:00:00.
显示的警告是数据在'blog_date'被截断.现在,我不知道如何解决使用NOW()获取当前时间的问题.下面是我的blog_details表,insert命令和错误:
The warning that showed was data was truncated at 'blog_date'. Now I don't know how to solve this problem of acquiring current time using NOW(). Below is my blog_details table, the insert command, and the error:
CREATE TABLE `blog_details` ( `blog_id` int(11) NOT NULL AUTO_INCREMENT,
`title` char(200) NOT NULL, `blog_content` varchar(2500) NOTNULL,
`blog_date` datetime NOT NULL, `cat_name` varchar(30) NULL,
PRIMARY KEY (`blog_id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
INSERT INTO `blog_details` (`title`, `blog_content`, `blog_date`, `cat_name`)
VALUES('Breaking Bad TV Series', 'Best series evar', 'NOW()', 'Uncategorized');
+ --------- + ------ + ----------------------------- ------------------- +
|级别|验证码|留言|
+ --------- + ------ + -------------------------------- ---------------- +
|警告| 1265 |第1行的'blog_date'列的数据被截断|
+ --------- + ------ + -------------------------------- ---------------- +
+---------+------+------------------------------------------------+
| Level | Code | Message |
+---------+------+------------------------------------------------+
| Warning | 1265 | Data truncated for column 'blog_date' at row 1 |
+---------+------+------------------------------------------------+
推荐答案
您要插入的是字符串"NOW()"
,它与函数调用NOW()
完全不同.
What you're inserting is the string "NOW()"
which is completely different from the function call NOW()
.
由于"NOW()"
不是有效日期,因此其为零.
As "NOW()"
is not a valid date, it goes in as zero.
从中删除引号应该可以解决问题.
Removing the quotes from that should fix the issue.
这篇关于在datetime数据类型中插入NOW()值将返回0000-00-00 00:00:00的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!