Shimon Geld
Shimon Geld

Reputation: 89

How to add char to calculated field in SSRS

I want to put in the field the following expression: =Year(Fields!TaskOpenDate.Value) + "-" + Month(Fields!TaskOpenDate.Value) that I want is to show in the field like this: 02-2014. How do I do that?

Upvotes: 1

Views: 1082

Answers (3)

Jithin Shaji
Jithin Shaji

Reputation: 6073

This will give your required date format

=   Right("0"+CStr(Month(Fields!TaskOpenDate.Value)),2) +"-"+ 
    CStr(Year(Fields!TaskOpenDate.Value))

Upvotes: 0

Ian Preston
Ian Preston

Reputation: 39566

Since it seems like TaskOpenDate is already a DateTime, you can just Format this the way you want:

=Format(Fields!TaskOpenDate.Value, "MM-yyyy")

Upvotes: 3

Dan Scally
Dan Scally

Reputation: 2042

You're close but Year() and Month() return data as Integers. You're then using the + operator on the Integers returned by Year() and Month() to try and concatenate those with a string, which is confusing it.

Just convert the return from Year() and Month() to string as well, and it'll be fine:

=CStr(Month(Fields!TaskOpenDate.Value)) + "-" + CStr(Year(Fields!TaskOpenDate.Value))

Upvotes: 0

Related Questions