Feeds:
Posts
Comments

Posts Tagged ‘SQL SERVER – Get Month Name from date’

How to get the Month Name from Date ? Have been questioned numerous times and we do have its solution via DATENAME function. However, today we will achieve the same solution using FORMAT function, introduced in SQL Server 2012 as well. Given below are the two methods that help in identifying the Month Name from Date in SQL Server 2005 & above as well as SQL Server 2012 & above.

Method 1 :
Script supported in SQL Server 2005 and above :

 --This script will work in SQL Server 2005 and above
Declare @Datetime as datetime
Set @Datetime =getdate()

SELECT DATENAME(month, @Datetime) AS [Month Name]
--OR
SELECT DATENAME(mm, @Datetime) AS [Month Name]
--OR
SELECT DATENAME(m, @Datetime) AS [Month Name]
--OUTPUT

get month name from date1.1

Method 2 :
Script supported in SQL Server 2012 and above :

 --This script will work in SQL Server 2012 and above
Declare @Datetime as datetime
Set @Datetime =getdate()
Select FORMAT(@Datetime,'MMMM') AS [Month Name]
--OUTPUT

Get month name from date-1
Have you come across any other method ? Do share.

Advertisements

Read Full Post »