MySQL 1292 Truncated incorrect datetime value: '2020-01-02 07:15:00'

Steve :

I am trying to insert a Datetime field by concatenating a Date and Time field.

Om my local Mysql its working with a warning message , on the server its failing with the same message.

Any help on this please

Source table (shift details) -

CREATE TABLE IF NOT EXISTS `shift_t` (
  `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `Name` varchar(20) NOT NULL,
  `NameShort` varchar(10) NOT NULL,
  `WeekType` varchar(4) NOT NULL,
  `DayOfWeek` char(3) NOT NULL DEFAULT '0',
  `StartTime` time NOT NULL DEFAULT '00:00:00',
  `EndTime` time NOT NULL DEFAULT '00:00:00',
  `LineID` int(10) unsigned NOT NULL DEFAULT 0,
  `PlantID` int(10) unsigned NOT NULL
)

Example of table to load ..

CREATE temporary TABLE shifttemp1 (
  plantid int(10) unsigned NOT NULL,
  lineid int(10) unsigned NOT NULL,
  starttime time NOT NULL,
  shiftstart1 datetime DEFAULT NULL
);

INSERT INTO shifttemp1
( plantid,lineid,starttime,shiftstart1)
SELECT    shf.plantid, 
          shf.lineid,
             shf.starttime,
          Str_to_date(CONCAT('2020-01-02', ' ', shf.starttime), '%Y-%m-%d %H:%i')  shiftstart1  
   from shift_t  shf 
    WHERE shf.dayofweek = 'MON' 
    AND shf.lineid = 31 
     AND shf.nameshort = 'DAY'     ;

Error message

1292 Truncated incorrect datetime value: '2020-01-02 07:15:00'
GMB :

You are missing the second part. So basically you want to change this:

str_to_date(concat('2020-01-02', ' ', shf.starttime), '%Y-%m-%d %H:%i')

To:

str_to_date(concat('2020-01-02', ' ', shf.starttime), '%Y-%m-%d %H:%i:%s')

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=5673&siteId=1