MySQL date format to convert to YYYY-MM-DD?

How to convert MySQL date format to from YYYY-MM-DD?

Add Comment
1 Answer(s)

Use STR_TO_DATE() method from MySQL to convert.

DATE_FORMAT(STR_TO_DATE(myVal, '%d.%m.%y'), '%Y-%m-%d')

Note that the year is %y (lowercase “y”) in STR_TO_DATE and %Y (uppercase “Y”) in DATE_FORMAT.

The lowercase version is for two-digit years and the uppercase is for four-digit years.

Answered on April 7, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.