Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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.
DATE_FORMAT
Use STR_TO_DATE.
STR_TO_DATE
Try
SELECT STR_TO_DATE('12-Mar-2013','%d-%M-%Y'); -> 2013-03-12
Add a comment
This should do the trick
SELECT DATE_FORMAT(STR_TO_DATE('12-Mar-2013','%d-%b-%Y'), '%Y-%d-%m');
Required, but never shown
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.
Explore related questions
See similar questions with these tags.
DATE_FORMATconverts DATE to STRING.