在mysql insert中使用STR_TO_Date()

在mysql insert中使用STR_TO_Date(),mysql,Mysql,我有如下mysql表 CREATE TABLE `installments` ( `id` int(11) NOT NULL, `order` int(11) NOT NULL, `payment_date` date DEFAULT NULL, `cost` int(11) NOT NULL, `is_paid` int(11) NOT NULL DEFAULT '0', `is_removed` int(11) NOT NULL DEFAULT '0' ) ENGINE=InnoDB DE

我有如下mysql表

 CREATE TABLE `installments` (
`id` int(11) NOT NULL,
`order` int(11) NOT NULL,
`payment_date` date DEFAULT NULL,
`cost` int(11) NOT NULL,
`is_paid` int(11) NOT NULL DEFAULT '0',
`is_removed` int(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
当我运行insert station时

     INSERT INTO installments (`order`,payment_date,cost) VALUES     (1,STR_TO_DATE('5-30-2017','%m-%d-%y'),14
给我 数据截断:截断的日期值不正确:“5-30-2017”

有什么办法解决这个问题吗

INSERT INTO installments (`order`,payment_date,cost) VALUES     (1,STR_TO_DATE('5-30-2017','%m-%d-%y'),14

您使用的预期月份格式为前导零(01-12)。您需要删除前导零的
%c

INSERT INTO installments (`order`,payment_date,cost) VALUES
 (1,STR_TO_DATE('5-30-2017','%c-%d-%Y'),14);

你能在交月费之前填上你的月数吗?它正在寻找一个2位数的月份(01-12),而您正在传递一个单位位数的月份。我收回这一点,尝试
%c
而不是
%m
您是否尝试了mysql默认的Y-m-d格式而不是m-d-Y格式?请始终在mysql中以Y-m-d格式存储日期。如果需要在其他表单中选择,请使用正确的字符串函数DATE\u格式!它也应该是%Y而不是%Y,因为它是4位数而不是2位数。我不确定这是否有帮助。实际上,在我的服务器上运行临时表时,
%m-%d-%y
和“%c-%d-%y”发出了该警告,而
%c-%d-%y
工作正常,所以应该可以工作。
INSERT INTO installments (`order`,payment_date,cost) VALUES
 (1,STR_TO_DATE('5-30-2017','%c-%d-%Y'),14);