12

I come up with an error while inserting the following data into MySQL. How can I fix it?

ERROR 1292: Incorrect datetime value: '17/07/2013 18:33:55' for column 'TimeStamp' at row 1

SQL Statement:

INSERT INTO `wngtest`.`sitereading` (`idSiteReading`, `TimeStamp`, `SiteLocation`, `Flow`, `Temperature1`, `Temperature2`) VALUES ('1', '17/07/2013 18:33:55', 'WNGSite1', '13.1', '81', '45')

ERROR 1292: Incorrect datetime value: '17/07/2013 18:18:53' for column 'TimeStamp' at row 1

SQL Statement:

INSERT INTO `wngtest`.`sitereading` (`idSiteReading`, `TimeStamp`, `SiteLocation`, `Flow`, `Temperature1`, `Temperature2`) VALUES ('2', '17/07/2013 18:18:53', 'WNGSite1', '13', '80', '45')

ERROR 1292: Incorrect datetime value: '17/07/2013 18:03:54' for column 'TimeStamp' at row 1

SQL Statement:

INSERT INTO `wngtest`.`sitereading` (`idSiteReading`, `TimeStamp`, `SiteLocation`, `Flow`, `Temperature1`, `Temperature2`) VALUES ('3', '17/07/2013 18:03:54', 'WNGSite1', '12.7', '80', '45')

ERROR 1292: Incorrect datetime value: '17/07/2013 17:48:54' for column 'TimeStamp' at row 1

SQL Statement:

INSERT INTO `wngtest`.`sitereading` (`idSiteReading`, `TimeStamp`, `SiteLocation`, `Flow`, `Temperature1`, `Temperature2`) VALUES ('4', '17/07/2013 17:48:54', 'WNGSite1', '12.7', '80', '45')

ERROR 1292: Incorrect datetime value: '17/07/2013 17:33:55' for column 'TimeStamp' at row 1

SQL Statement:

INSERT INTO `wngtest`.`sitereading` (`idSiteReading`, `TimeStamp`, `SiteLocation`, `Flow`, `Temperature1`, `Temperature2`) VALUES ('5', '17/07/2013 17:33:55', 'WNGSite1', '12.8', '80', '45')

ERROR 1292: Incorrect datetime value: '17/07/2013 17:18:55' for column 'TimeStamp' at row 1

SQL Statement:

INSERT INTO `wngtest`.`sitereading` (`idSiteReading`, `TimeStamp`, `SiteLocation`, `Flow`, `Temperature1`, `Temperature2`) VALUES ('6', '17/07/2013 17:18:55', 'WNGSite1', '12.9', '80', '45')
0

2 Answers 2

12

In MySql dates should be inserted in yyyy-mm-dd format

Try using the format:

2013-07-17 17:18:55

Full Insert Statement:

INSERT INTO wngtest.sitereading 
(idSiteReading, TimeStamp, SiteLocation, Flow, Temperature1, Temperature2) 
VALUES ('1', '2013-07-17 18:33:55', 'WNGSite1', '13.1', '81', '45');
Sign up to request clarification or add additional context in comments.

1 Comment

but I type '2100-06-04 00:00:00' into a query mysql also errs
11

Alternatively, you can automatically re-format your date string to SQL-99 format using STR_TO_DATE():

STR_TO_DATE( '17/07/2013 18:33:55', '%d/%m/%Y %H:%i:%s')

So the INSERT statement would be:

INSERT INTO wngtest.sitereading 
(idSiteReading, TimeStamp, SiteLocation, Flow, Temperature1, Temperature2) 
VALUES ('1', 
STR_TO_DATE( '17/07/2013 18:33:55', '%d/%m/%Y %H:%i:%s'), 
'WNGSite1', '13.1', '81', '45');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.