1

I have a bunch of txt files that contains a lot of data, including a date in format

dd-mm-YYYY

for example this date

15-03-2014

Researching around here i found a way to convert this date to insert in database in the correct date format YYY-mm-dd

the query is

STR_TO_DATE('$array[12]', '%Y-%m-%d')

But i'm having weird results like

2019-07-20

How can i correctly insert them to database any tips of what i'm doing wrong?

4

1 回答 1

4

第二个参数应该是您的日期存储的格式,而不是您要查找的格式,它是 always YYYY-MM-DD。所以:

STR_TO_DATE('$array[12]', '%Y-%m-%d')

应该:

STR_TO_DATE('$array[12]', '%d-%m-%Y')
于 2013-07-30T13:49:44.453 回答