0

I'm trying to copy a varchar column which contains dates in the format YYYY-MM-DD to a date column using str_to_date.

My query is: UPDATE subscribers SET srtdt = STR_TO_DATE(StartDate, '%Y%m%d%');

I am getting error 1411: Incorrect datetime value: '2001-09-16'... This seems to be happening on the first row.

I have searched a lot for this but cannot find why this is happening - all other answers point towards the string being in the wrong format etc, and that doesn't seem to be the case with my problem.

Thanks

  • Fast guess: you would need %Y-%m-%d with the - and without your last % – joanolo Jan 10 '17 at 9:05
  • Eh? '2001-09-16' is a valid DATE or DATETIME. So, why run it through STR_TO_DATE()? – Rick James Jan 11 '17 at 0:37
1

Try it:

UPDATE subscribers SET srtdt = STR_TO_DATE(StartDate, '%Y-%m-%d');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.