0

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.

1
  • 1
    DATE_FORMAT converts DATE to STRING. Commented Mar 13, 2013 at 8:24

2 Answers 2

5

Use STR_TO_DATE.

Try

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

->   2013-03-12
Sign up to request clarification or add additional context in comments.

Comments

3

This should do the trick

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.