;

How to Get the Month Name from a Date in SQL Server


Tutorialsrack 13/01/2020 SQL Server

In this article, we will learn about how to get the month name from a date or using a given date in SQL Server.

To get the month name from a given date in SQL Server, we can use DATENAME() Built-in Function, the query is as follows:

Example 1:

Example
-- To Get the Month Name From a Current Date
SELECT DATENAME(mm, GETDATE()) as 'Month Name';
Output

Month Name

------------------------------

January

(1 row(s) affected)

Example 2:

Example
-- To Get the Month Name From a Given Date
SELECT DATENAME(mm, '2020-01-04 11:46:26.441') as 'Month Name';
Output

Month Name

------------------------------

January

(1 row(s) affected)

Example 3:

Example
-- To Get the Month Name From a Date without Time
SELECT DATENAME(mm, '2020-02-11') as 'Month Name';
Output

Month Name

------------------------------

February

(1 row(s) affected)

If you want the output in a different language then you have to change the login default language. To set the language you need to select the language from the System View, the query is as follows:

Code - To select the language from the System View
-- To get the list of the languages
SELECT * FROM SYS.SYSLANGUAGES;

To Set the language, use SET LANGUAGE statement with the name of a language name from the sys.syslanguages System View.

Code - To set the Language and get the month name in the German Language.
-- To get the Month name in German Language 
SET LANGUAGE German
SELECT DATENAME(mm, '2020-02-11') as 'Month Name';
Output

Month Name

------------------------------

Februar

(1 row(s) affected)

I hope this article will help you to understand how to get the month name from a date or using a given date in SQL Server.

Share your valuable feedback, please post your comment at the bottom of this article. Thank you!


Related Posts



Comments

Recent Posts
Tags