/////////////////////
////////// Result
February
Feb
DECLARE @MyMonth varchar(10)='2'
DECLARE @dates datetime2 = '1900-'+@MyMonth+'-01';
SELECT DATENAME(month, DATEADD(month, @MyMonth-1, CAST('2008-01-01' AS datetime))) [MonthName]
----------
Or
select DATENAME(Month,'1900-'+@MyMonth+'-01') [MonthName]
----------
Or
--------------
or With Fn
SELECT {fn MONTHNAME(@dates)} [MonthName];
SELECT FORMAT(@dates, 'MMMM') AS [MonthName];
----------
Or Culture wise
SELECT
FORMAT(@dates, 'MMMM', 'en-US') AS 'en-US',
FORMAT(@dates, 'MMMM', 'es-es') AS 'es-es',
FORMAT(@dates, 'MMMM', 'de-de') AS 'de-de',
FORMAT(@dates, 'MMMM', 'en-GB') AS 'zh-cn';
----------
Or Frist 3 char
select left(DATENAME(Month,'1900-'+@MyMonth+'-01'),3) [MonthName]
////////// Result
February
Feb
No comments:
Post a Comment