Home > OS >  how to convert '202109' to 2021-09 in mysql
how to convert '202109' to 2021-09 in mysql

Time:10-13

how to convert '202109' to 2021-09 in MySQL,

I tied

select STR_TO_DATE('202109', '%Y-%m') and select DATE('202109', '%Y-%m')

all failed,

CodePudding user response:

I hope you have string. So I think no need to deal with date.

SELECT INSERT('202109', 5, 0, '-');

CodePudding user response:

Change %Y-%m to %Y%m them just use DATE_FORMAT to get formart what you want

select DATE_FORMAT( STR_TO_DATE('202109', '%Y%m'), '%Y-%m') as ym_formart
  • Related