Friday, August 26, 2011

How Do You Know the Name of the Month in the Monthly Index of T-SQL?

When working with reports, is that every time I'm looking for. Everyone gives the report date as input, and wants to show the month name in the report instead of the monthly index [1-12]. So how?

please use the below script to get the name of the month by month index.

DateName(month, convert( datetime, '2007-' + cast(month(getdate()) as varchar(2)) + '-01', 120))

Here month(getdate()) returns the current month index from getdate() function. Hope this helps...

No comments:

Post a Comment