Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

1292: Incorrect datetime value: '' for column at row 1

I am trying to load data from excel sheet to the below table on MYSQL 5.6 on windows 8.1 and I am getting 'Incorrect datetime value:' error.

Term date column is of DATETIME data type and the data has null values in the excel sheet which I am trying to insert into the table.

I did some research and found that the problem is with the SQL strict mode. But I am not able to figure out how to disable or modify the SQL strict mode.

I in fact tried this SET SESSION sql_mode='ALLOW_INVALID_DATES' but no luck.

Some said editing my.ini file in installation directory will help but I am not able to find it in the installation directory.

can any one please help me resolve this issue.

create table EMPLOYEE(EMP_ID integer(10),
EMP_NAME char(25),
SALARY integer(25),
START_DATE datetime,
TERM_DATE datetime DEFAULT '1900-01-01',
PRIMARY KEY (EMP_ID));

Error Message:

15:23:08    INSERT INTO `mith`.`EMPLOYEE` (`EMP_ID`, `EMP_NAME`, `SALARY`, `START_DATE`, `TERM_DATE`) VALUES ('26', 'Will Banker', '90000', '00:00.0', '')  1292: Incorrect datetime value: '' for column 'TERM_DATE' at row 1  
like image 500
Mithun Raj Avatar asked Feb 15 '15 19:02

Mithun Raj


People also ask

Can we change date format in MySQL?

In a MySQL database, the DATE_FORMAT() function allows you to display date and time data in a changed format. This function takes two arguments. The first is the date/datetime to be reformatted; this can be a date/time/datetime/timestamp column or an expression returning a value in one of these data types.

How do you use timestamp?

The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC. A DATETIME or TIMESTAMP value can include a trailing fractional seconds part in up to microseconds (6 digits) precision.


1 Answers

In MySQL, '' (an empty string) is different from a null. If you want a null value, you should use an explicit null:

INSERT INTO `mith`.`EMPLOYEE` 
(`EMP_ID`, `EMP_NAME`, `SALARY`, `START_DATE`, `TERM_DATE`)
VALUES ('26', 'Will Banker', '90000', '00:00.0', null)
like image 164
Mureinik Avatar answered Sep 26 '22 13:09

Mureinik