I have a month column in my table. The month numbers are stored in this month column like 1 for january, 2 for feb and so on.
How do I convert the numbers into month names such as january, february, march etc.
Please do as follows: Select a blank cell next to the sales table, type the formula =TEXT(A2*29,"mmm") (Note: A2 is the first number of the Month list you will convert to month name), and then drag the AutoFill Handle down to other cells. Now you will see the numbers (from 1 to 12) are converted to normal month names.
To convert month number to month name we have to use a function MONTHNAME(), this function takes date column or a date as a string and returns the Month name corresponding to the month number.
select to_char(SYSDATE,'Month') from dual; It gives unformatted month name, with spaces, for e.g. May would be given as 'May '.
To_char formats a DATE into a string using the given format mask. To_date converts a STRING into a date using the format mask. Your client then displays that date using a format mask (set at session/instance level).
SELECT TO_CHAR(TO_DATE(7, 'MM'), 'MONTH') AS monthname FROM DUAL;
outputs
monthname
---------
JULY
If you really want the month names in lower case or capitalised, you can also use:
TO_CHAR(TO_DATE(7, 'MM'), 'month')
TO_CHAR(TO_DATE(7, 'MM'), 'Month')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With