Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract Month/Year from Date in SSRS 2008

I am using SQL Server SSRS 2008 version and I need to extract out of a date field, the Month and Year values. For example from 2013-01-11 21:11:29.340, I need the report to display “January 2013”

In design view, in the cell where I want the information to display, where the ‘Expression’ option from the pull down menu, I put

= DATENAME(MONTH, DesiredDate) & DATENAME(YEAR, DesiredDate) .

And got an error message.

BTW, the ‘DesiredDate’ comes from the SQL code in the Query Designer.

like image 832
Joe Avatar asked Jan 14 '23 21:01

Joe


1 Answers

In SQL Server to concatenate values you will need a + between the values:

DATENAME(MONTH, DesiredDate) +' '+ DATENAME(YEAR, DesiredDate)

You might need to use the &' '& which will add the whitespace between the values:

DATENAME(MONTH, DesiredDate) &' '& DATENAME(YEAR, DesiredDate)

Edit #1, based on your comment, you can use the following in the Expression window:

=MonthName(Month(Fields!desireddate.Value)) &" "& Year(Fields!desireddate.Value)

Note: I just tested this in SSRS 2008 and it returned the result that you want.

like image 158
Taryn Avatar answered Mar 19 '23 03:03

Taryn