4

I have date in this format 5 Mar 1985 0:00 stored in table as VARCHAR.
I want to convert it into Datetime, I am using the 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.

Himanshu
  • 31,810
  • 31
  • 111
  • 133
user1369905
  • 663
  • 2
  • 7
  • 12

2 Answers2

5

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 |
+---------------------+
Devart
  • 119,203
  • 23
  • 166
  • 186
1

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

%m = month in integer %M = month in string(ex: Mar)

Cosmin
  • 1,482
  • 12
  • 26