Wednesday, March 7, 2012

Date format - Parameter/Field

Hi,

I have some difficulties to format a Date value in my reporting service.

As you know you can use this kind of expression:

=DateTime.Parse(Parameters!ReportingDate.Value).ToString("dd/MM/yyyy")

But it does not work, and when I just want to use the format property of the textbox content such as "dd/MM/yyyy", it displays "dd/MM/yyyy", not the real formatted data, this property works for "=Today()" but not for parameters and fields. What is the diffrence?

Have you an idea to format a Parameter/Field of Date type such as dd/MM/yyyy?

Many thanks!

Vin,

You can make your parameter of data type DateTime, this would eliminate the need to parse a string. If not, try

Format(CDate(Parameters!Report_Parameter_0.Value),"d")

Ham

|||

With your code, I get this error:

Cast from string "20061222" to type 'Date' is not valid.

Strange because the string has a correct date format :S

|||

Vin,

What's your Parameter data type?

Ham

|||

Also,

the value that is stored in this parameter.

Ham

|||

The parameter is an integer, it s the reason why I m using now:

=DateTime.Parse(Parameters!ReportingDate.Value.ToString())

The problem is the value of ReportingDate is "20061222" and to work as DateTime you have to have "2006/12/22", after you can display it as you want with ToString function.

I would like to have this format 2006/12/22 with / in fact, but properly...

|||

Vins,

That's a tough one, if you're using integer data type for Datetime. I guess my approach would be to change to integer into a string value

LEFT(Parameters!ReportingDate.Value.ToString,4) & "/" & Mid(Parameters!ReportingDate.Value.ToString,5,2) & "/" & RIGHT(Fields!SSN.Value,2)

The catch here is that you'll have to return always 4 digit years, 2 digit months and 2 digit days, instead of 2007/1/1 you would need 2007/01/01

Ham

|||Thanks Ham, it s working very well ;-)

No comments:

Post a Comment