skip to Main Content

I try to insert values into a new table. This is the insert with certain date format (dd/mm/yyyy h:m):

INSERT INTO `sport` (`TIME`, `HOME`, `VISIT`, `HOME_RESULT`, `VISIT_RESULT`) VALUES ('20/07/2024 19:15','Dortmund','Bayern','5','3');

and this is the create table scheme:

CREATE TABLE `sport` (
  `ID` MEDIUMINT NOT NULL AUTO_INCREMENT,
  `TIME` datetime NOT NULL,
  `HOME` varchar(200) NOT NULL,
  `VISIT` varchar(200) NOT NULL,
  `HOME_RESULT` int(3) NOT NULL,
  `VISIT_RESULT` int(3) NOT NULL,
  PRIMARY KEY (ID)
);

But I get the following error:

ERROR 1292 (22007): Incorrect datetime value: '20/07/2024 19:15' for column `sport`.`sport`.`TIME` at row 1

How can I fix this problem with datetime format?

Thanks in advance

2

Answers


  1. you should use the YYYY-MM-DD HH:MM:SS format:

    INSERT INTO sport (TIME, HOME, VISIT, HOME_RESULT, VISIT_RESULT)
    VALUES ('2024-07-20 19:15:00', 'Home Team', 'Visit Team', 3, 2);
    
    Login or Signup to reply.
  2. The issue is due to MySQL’s default datetime format, which is YYYY-MM-DD HH:MM:SS. Your input format (DD/MM/YYYY HH:MM) does not match this format

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search