How to convert YYYYMMDD date to YY-MM-DD in MySQL query

I have a date column that is in the format YYYYMMDD or 20120101. This is because SAP saves it in this format, so it cannot change this.

How can I convert this to YYYY-MM-DD format in a MySQL query? In DB2, I used the to_date () function.

In MySQL, I try to execute the STR_TO_STRING () function, but it returns "null".

  SELECT STR_TO_DATE(VBAP.ERDAT,'%Y-%m-%d') FROM VBAP
+5
source share
1 answer

It works.

date_format(str_to_date(VBAP.ERDAT, '%Y%m%d'),'%Y-%m-%d')
+6
source

All Articles