STR_TO_DATE () MySQL function

I have a date in this format 5 Mar 1985 0:00 , stored in the table as VARCHAR .
I want to convert it to Datetime , I use STR_TO_DATE() as follows:

 SELECT STR_TO_DATE(birth_date, '%d %m %Y %h:%i') FROM student WHERE pk = 29 

But it returns NULL .

+4
source share
2 answers

Try this format - '%e %b %Y %k:%i' , for example -

 SELECT STR_TO_DATE('5 Mar 1985 2:33', '%e %b %Y %k:%i') dt; +---------------------+ | dt | +---------------------+ | 1985-03-05 02:33:00 | +---------------------+ 
+5
source

Try STR_TO_DATE(birth_date, '%d %M %Y %h:%i') instead

%m = month in integer %m = month in a row (ex: Mar)

+1
source

Source: https://habr.com/ru/post/1432930/


All Articles