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
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
Reblogged this on Sutoprise Avenue, A SutoCom Source.