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:
-- To Get the Month Name From a Current Date
SELECT DATENAME(mm, GETDATE()) as 'Month Name';
Month Name
------------------------------
January
(1 row(s) affected)
Example 2:
-- To Get the Month Name From a Given Date
SELECT DATENAME(mm, '2020-01-04 11:46:26.441') as 'Month Name';
Month Name
------------------------------
January
(1 row(s) affected)
Example 3:
-- To Get the Month Name From a Date without Time
SELECT DATENAME(mm, '2020-02-11') as 'Month Name';
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:
-- 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.
-- To get the Month name in German Language
SET LANGUAGE German
SELECT DATENAME(mm, '2020-02-11') as 'Month Name';
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!
Comments