Reputation: 117
CREATE TABLE orders(
order_id INTEGER PRIMARY KEY,
customer_id INTEGER,
order_date DATE,
ship_date DATE
);
INSERT INTO orders
VALUES
(1, 1200, '2013-23-10', '2013-28-10');
Is there anything wrong with the above code?
Upvotes: 1
Views: 11870
Reputation: 108410
Date format is 'YYYY-MM-DD'
.
23
and 28
are not valid values for MM
month component.
The error returned by MySQL is expected behavior.
Nothing necessarily wrong with what you are doing, if you are want MySQL to return an error message.
If you are wanting the statement execution to be successful, and to add a row to orders
table, supply valid date values for the DATE columns.
Either change the literal values to match the format expected by MySQL, or use STR_TO_DATE
function to convert the string from a specified format.
... , '2013-10-23' , ...
or
... , STR_TO_DATE('2013-23-10','%Y-%d-%m') , ...
Upvotes: 0
Reputation: 30819
You are using 'YYYY-dd-MM' format whereas you need to use 'YYYY-MM-dd', try the following:
INSERT INTO orders VALUES (1, 1200, '2013-10-23', '2013-10-28');
Upvotes: 2