MONTHNAME

MONTHNAME is an SQL function that retrieves the name of the month from a given date.

MONTHNAME(date)

  • date: This parameter represents the date from which the function will extract the month name. The data type of this parameter can be a date, datetime, or a string in an appropriate format.

Example

SELECT MONTHNAME('2021-05-20') AS 'Month';

Output

| Month |
|-------|
| May |

Explanation

The MONTHNAME function in SQL is used to get the name of the month from the specified date. In the above example, it is extracting the month name (May) from the date ‘2021-05-20’.

MONTHNAME( date )

  • date: The date value from which the name of the month is retrieved. It can be any valid date expression. This function will return the full name of the month corresponding to the date provided as a string.

Example

SELECT MONTHNAME('2022-09-15') AS Month_Name;

Output

+------------+
| Month_Name |
+------------+
| September |
+------------+

Explanation

In the above SQL command, the MONTHNAME function is used to extract the month name from the date provided (‘2022-09-15’). The result is ‘September’.

MONTHNAME(date)

  • date: This parameter accepts a DATE or an expression that can be evaluated to a DATE. It represents the date from which the month name is to be extracted. The value returned by the MONTHNAME function is a string representing the name of the month of the input date in uppercase.

Example

SELECT TO_CHAR(TO_DATE('14-JUL-21', 'DD-MON-YY'), 'MONTH') AS MonthName FROM dual;

Output

MonthName
---------
JULY

Explanation

This command extracts the full month name from the provided date string ‘14-JUL-21’. The TO_DATE function converts the date string into a date format, and the TO_CHAR function converts this date into a string of full month name. The SQL query returns ‘JULY’ as the full month name.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.