Most major RDBMSs provide at least one function that enables us to return the month name from a date.
MySQL
MySQL has a MONTHNAME()
function that is designed specifically to return the month name from a date:
SELECT MONTHNAME('2030-12-25');
Result:
December
MySQL also has a DATE_FORMAT()
function that can achieve the same effect.
The language used for the month name is controlled by the value of the lc_time_names
system variable. See How to Set the Locale for the Current Connection in MySQL for more information.
See 2 Functions that Return the Month Name from a Date in MySQL for examples of both functions, including how to return the short month name.
SQL Server
There are several ways to do it in SQL Server. One way is to use the DATENAME()
function with month
as the first argument:
SELECT DATENAME(month, '2030-09-01');
Result:
September
That code will work on any DBMS that supports T-SQL. For example, you can use it with Windows Azure SQL Database and Azure SQL Edge.
See 3 Ways to Get the Month Name from a Date in SQL Server for more options. This includes the FORMAT()
function, which allows you to specify a language for the month name.
Oracle
To get the full month name in Oracle, use the TO_CHAR(datetime)
function with the MONTH
format element:
SELECT TO_CHAR(DATE '2035-10-03', 'MONTH')
FROM DUAL;
Result:
OCTOBER
See How to Get the Month Name from a Date in Oracle for more options.
PostgreSQL
PostgreSQL also has a TO_CHAR()
function that works similar to Oracle’s:
SELECT TO_CHAR(TIMESTAMP '2020-12-16 10:41:35', 'Month');
Result:
December
See Get the Month Name from a Date in PostgreSQL for more options.
MariaDB
Like MySQL, MariaDB has both a MONTHNAME()
function and a DATE_FORMAT()
function.
Here’s an example of the later:
SELECT DATE_FORMAT('2021-08-19', '%M');
Result:
August
One difference between the MariaDB and MySQL versions of DATE_FORMAT()
is that MariaDB accepts a third argument that allows you to specify the locale (MySQL doesn’t). This means that you can specify the locale from within the function in MariaDB, without having to change the locale of the current session.
See 3 Ways to Get the Month Name from a Date in MariaDB for more examples.