2
votes

I have a table with dates in this format "12/14/2017" and I want to create another column that separates month from this date string and states it like "January" not "01". I think I need a mix of CASE function with some kind of DATE function.

Table:

Column A   
12/14/2017
12/11/2017
2/16/2018
1/2/2017

Output I need which I will Column B:

Column A    Column B (Output)
12/14/2017  December
12/11/2017  December
2/16/2018   February
1/2/2017    January
2

2 Answers

1
votes

You can convert the value to a date and then to a month string:

DATE_FORMAT(TO_DATE(columnA, 'MM/DD/YYYY', 'MMMM')
0
votes
SELECT columnA,  
    CASE EXTRACT(MONTH FROM TO_DATE(columnA,'mm/dd/yyyy')) 
        WHEN 1 THEN 'January' 
        WHEN 2 THEN 'February' 
        WHEN 3 THEN 'March'
        WHEN 4 THEN 'April'         
        WHEN 5 THEN 'May' 
        WHEN 6 THEN 'June' 
        WHEN 7 THEN 'July'  
        WHEN 8 THEN 'August'
        WHEN 9 THEN 'September' 
        WHEN 10 THEN 'October' 
        WHEN 11 THEN 'November' 
        WHEN 12 THEN 'December'  
    END AS columnB
FROM yourTable