0

I have to extract the month name and year from the string of the form mmm-yy (Eg. Jan-20) using mysql query. I have tried the following query it returns only NULL. The query is:

SELECT monthname(mon)FROM month_extract_plan

Sample data: 

Jan-20
Feb-20
Dec-19
FRECEENA FRANCIS
  • 181
  • 2
  • 13

2 Answers2

1

You can use a Query like this:

SELECT 
    SUBSTRING_INDEX(str, '-', 1)  as MyMonth,
    SUBSTRING_INDEX(str, '-', -1) as MyYear
FROM month_extract_plan;
Bernd Buffen
  • 14,525
  • 2
  • 24
  • 39
0

Use STR_TO:Date

SELECT monthname(STR_TO_DATE('Jan-20','%b-%y')) ,YEAR(STR_TO_DATE('Jan-20','%b-%y')) 

gets you

'January 2020

nbk
  • 45,398
  • 8
  • 30
  • 47