1

I'm trying to insert a date from a string in another table. The SELECT statement provides no error while the INSERT statement provides the error "Incorrect datetime value: '2015/06/08' for function str_to_date"
The data in the 1CON field is 2015/06/08

INSERT INTO dest
SELECT COALESCE(STR_TO_DATE(1CON, '%m/%d/%Y'),
STR_TO_DATE(1CON, '%Y/%m/%d')) 
FROM origin WHERE REC=4953;

And the SELECT statement:

SELECT COALESCE(STR_TO_DATE(1CON, '%m/%d/%Y'),
STR_TO_DATE(1CON, '%Y/%m/%d'))
FROM origin WHERE REC=4953;
  • I'm unsure about the syntax, but it seems weird to pass `2015/06/08` and `%m/%d/%Y` (month = 2015, day = 06, year = 08) in the same command. Did you mean `%Y/%m/%d`? – h2ooooooo Jul 16 '15 at 19:17

1 Answers1

1

insert dates as '2015-06-02' kinda format

insert datetimes as '2015-06-02 14:02:28'

yes, for June 2

Drew
  • 24,120
  • 9
  • 38
  • 72