Friday 24 June 2011

How to get month name from from SQL Server datetime field?

1) Below query return month name (from January to December) based on your record date.

select DATENAME(month,fieldname) from tablename 

2) Below query is used to get only three charecter from the selected month
select Convert(varchar(3),DATENAME(month,empdate)) from empdt  (or)
select Cast(DATENAME(month,empdate) as varchar(3)) from empdt

No comments:

Post a Comment