yskeat
yskeat

Reputation: 17

mysql string to date

How can I convert a string/varchar like '12-Mar-2013' to date like 2013-03-12?

I tried

SELECT STR_TO_DATE('12-Mar-2013','%Y-%m-%d');

SELECT DATE_FORMAT('12-Mar-2013','%Y-%m-%d');

but both return null.

My current database version is 5.5.7-rc.

Upvotes: 0

Views: 189

Answers (2)

Ed Heal
Ed Heal

Reputation: 60007

This should do the trick

SELECT DATE_FORMAT(STR_TO_DATE('12-Mar-2013','%d-%b-%Y'), '%Y-%d-%m');

Upvotes: 3

Bjoern
Bjoern

Reputation: 16304

Use STR_TO_DATE.

Try

SELECT STR_TO_DATE('12-Mar-2013','%d-%M-%Y');

->   2013-03-12

Upvotes: 5

Related Questions