I have a column named strdate in MySQL database with a table named data. The strdate column is of type varchar(100)
I tried a couple of ways to use the select command to get results in a legitimate date format. When I succeed I want to update that column to a proper date type.
I started with this command:
SELECT DATE_FORMAT(STR_TO_DATE(strdate, '%e %M Y, %h %m'), '%H:%i') FROM data where topic = 26801;
But that gave me this un-successfull result:
Here are a couple of examples in the strdate column which I want to convert:
7 juni 2016, 22:04
19 juli 2011, 20:02
9 augustus 2022, 06:07
I read through this website: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-format
I assume that I have to write the comma and the colon in a literary way in the query. To summarize: How to compose the query in a way to select the dates in the given example (which are text strings) and convert them to a valid and proper date format. If that goes well I want to use the update command to adjust the type of the strdate column and insert the dates as real dates. Any help would be really appriciated.
Dutch month names can be output by
DATE_FORMAT(), but unfortunately MySQL does not support the reverse forSTR_TO_DATE():https://dev.mysql.com/doc/refman/8.0/en/locale-support.html
This feature to parse locale-specific month names was requested in this bug reported in 2012: https://bugs.mysql.com/bug.php?id=64023. You might like to click the "Affects Me" button for that bug, to try to raise the priority of implementing it.
In the meantime, I'm afraid you'll have to parse non-"en_US" month names yourself.
Here's a solution showing replacing three month names. For all 12 months, you would need more nested REPLACE() function calls. It's ugly, but it would work.
Output, tested in MySQL 8.3.0: