Specify language with MYSql - STR_TO_DATE


I have the following problem.

I need to parse a text to a date with MySql . The problem is that the text to be parsed is of the style: " 03-ene-17 ".

I used the STR_TO_DATE function in the following way:

STR_TO_DATE('03-ene-17', '%d-%b-%y');

The problem is that the default function only recognizes the abbreviations in English, so it is not able to parse my string.

I can modify my entry to change the abbreviations in Spanish by the English abbreviations. But I want to know if there is any other way a little smarter to do this.

asked by Galbi 18.07.2017 в 10:09

1 answer


The way I can think of is replacing the month at the same time as formatting:

STR_TO_DATE(REPLACE('03-ene-17', '-ene-', '-Jan-'), '%d-%b-%y') AS FECHA

It works, but it is laborious because you would have to do it for each month. If it is to implement in a frequently used query it would not be very practical, but if it is to create a date type field in a table that stores the date in a more malleable format (quite advisable) it can be useful.

Maybe someone will come up with a simpler way.

answered by 18.07.2017 / 11:11