Noam
Noam

Reputation: 3391

Convert unconventional string to mysql datetime in MySQL

I want to convert a field that represents a date-time but is currently a VARCHAR to a DATETIME field. Currently the representation looks like: 'Sun May 20 01:04:39 +0000 2012' I want to do this operation in a query.

Upvotes: 0

Views: 81

Answers (2)

John Woo
John Woo

Reputation: 263733

Use STR_TO_DATE

SELECT STR_TO_DATE('Sun May 20 01:04:39 +0000 2012', '%a %M %d %H:%i:%S +0000 %Y')

Upvotes: 4

Bgi
Bgi

Reputation: 2494

Use the DATE function.

This does the job and can be used inside queries.

Upvotes: 0

Related Questions