Error while inserting date - Incorrect date value:

Viewed 157751

I have a column called today and the type is DATE.

When I try to add the date in the format '07-25-2012' I get the following error:

Unable to run query:Incorrect date value: '07-25-2012' for column

9 Answers

You can use "DATE" as a data type while you are creating the table. In this way, you can avoid the above error. Eg:

CREATE TABLE Employee (birth_date DATE);
INSERT INTO Employee VALUES('1967-11-17');

I had a different cause for this error. I tried to insert a date without using quotes and received a strange error telling me I had tried to insert a date from 2003.

My error message:

Although I was already using the YYYY-MM-DD format, I forgot to add quotes around the date. Even though it is a date and not a string, quotes are still required.

You can use this code. It will work fine.

INSERT INTO table_name(today)  
VALUES(STR_TO_DATE('07-25-2012','%m-%d-%Y'));  

Actually you cannot directly store date as a string, you first need to convert string to date in a proper format for which we use STR_TO_DATE() function, which needs two arguments, first is date as a string and 2nd one is date format in which you are passing your first argument.

Make sure you add a single or double quote. I noticed that you must add "", so MySQL uses it as string.

INSERT INTO table_name values 
 ("2001-11-09");
Related