SandyK
SandyK

Reputation: 465

Mysql converting varchar column values to datetime

I have table column with datatype as VARCHAR(255) and value in it as "Dec 31 1969 18:00:00". I need to convert this value in date format like Y-m-d H:i:s i.e. 1969-12-31 18:00:00 Tried with the solution using STR_TO_DATE, but is not working anymore. I tried like -

SELECT STR_TO_DATE('Dec 31 1969 18:00:00','%M %d,%Y %h:%i:%s') 

BUt, this returns NULL.

Any help is appreciated. Thank you.

Upvotes: 0

Views: 26

Answers (1)

Usagi Miyamoto
Usagi Miyamoto

Reputation: 6289

  • Remove the comma (,) from the format.
  • %M is the full name of the month, not abbreviated, like %b.
  • %h is 12-hour hours value. Use %H or use %T for the whole time part.

Try something like this:

SELECT STR_TO_DATE('Dec 31 1969 18:00:00','%b %d %Y %T') 

Upvotes: 1

Related Questions