SQL DML: Incorrect date value (MySQL)

强颜欢笑 提交于 2019-12-04 08:14:47

As documented under Date and Time Literals:

MySQL recognizes DATE values in these formats:

  • As a string in either 'YYYY-MM-DD' or 'YY-MM-DD' format. A “relaxed” syntax is permitted: Any punctuation character may be used as the delimiter between date parts. For example, '2012-12-31', '2012/12/31', '2012^12^31', and '2012@12@31' are equivalent.

  • As a string with no delimiters in either 'YYYYMMDD' or 'YYMMDD' format, provided that the string makes sense as a date. For example, '20070523' and '070523' are interpreted as '2007-05-23', but '071332' is illegal (it has nonsensical month and day parts) and becomes '0000-00-00'.

  • As a number in either YYYYMMDD or YYMMDD format, provided that the number makes sense as a date. For example, 19830905 and 830905 are interpreted as '1983-09-05'.

Therefore, the expression 2013-05-21 is not a valid MySQL date literal (it is in fact an arithmetic expression, consisting of two subtractions: it results in the integer 1987). In order to comply with one of the literal formats detailed above, you must either quote your date literal as a string and/or remove the delimiters.

You are missing with ' single quotes around the issue_date values for my test it inserts the records successfully

Try this

INSERT INTO official_receipt(student_no , academic_year, trimester, or_no, issue_date, received_from, amount_of, issued_by, doc_type, form_of_payment)
VALUES
    (201201121, 'AY201314', '1', 029940, '2013-05-21', 'NAME', 20000.00, NULL, 'DOWN', 'INST'),
    (201201121, 'AY201314', '1', 029944, '2013-07-23', 'NAME', 8000.00, NULL, 'INST', 'INST'),
    (201201101, 'AY201314', '1', 029941, '2013-05-21', 'NAME', 56650.00, NULL, 'FULL', 'CASH'),
    (201201037, 'AY201314', '1', 029942, '2013-05-21', 'NAME', 56650.00, NULL, 'FULL', 'CASH'),
    (201201142, 'AY201314', '1', 029943, '2013-05-21', 'NAME', 63800.00, NULL, 'FULL', 'CASH');

Here is your fiddle

You need to put the date literal in quotes. The error message says 1987 because the unquoted date is being read as the expression 2013 minus 5 minus 21, which is 1987.

Your dates can be like this: '2013-05-21' or '20130521' or a couple other formats covered in the documentation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!