sqldb2iseries-navigator

Convert decimal data values to month year text


I am given a table where the month is stored as a decimal value in one column, the year as a decimal in another column. In my query I want to return a text version of the month and year, such as...

from the database 2 and 2020 I want to display February 2020.

I started with...

date(concat(concat(concat(varchar(BDYREARN), '-'), varchar(BDMOEARN)), '-1')) AS Date_Earned

and was going to then use

monthName(Date_Earned)

but this feels like a very long way to go to get what I need.


Solution

  • Try this:

    TO_CHAR(DATE(DIGITS(DEC(BDYREARN, 4)) || '-' || DIGITS(DEC(BDMOEARN, 2)) || '-01'), 'Month YYYY')