Skip to content
Advertisement

How to convert/extract from YYYYMM to year and name of Month? Teradata SQL

So i got the date format in YYYYMM (eg. 201910 for Oct 2019), and what I want to have is 2019 and October (in full month name). Year number is easy, but to get the month name is a bit challenging.

In my data Calendar_Year_Month is the available field in the format of INT eg. 201910. I firstly converted to STRING and then adding just a random day 01 to become 20191001, then casting it to DATE format as Year_Month_Date.

I tried to use `TO_DATE(Year_Month_Date,’Month’) to get the Month name, however, it seems not working.

Any other options to achieve?

Advertisement

Answer

You were close:

CAST the int to a date and then apply TO_CHAR:

Extracting the year is simple:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement