1

I have a report that uses date params (so have to be datetime in SSRS, which sucks to start with). When the user enters a date such as "5/1" it creates a DateTimeOffset data type and I can't find anyway to cast it to anything else, format it, or concatenate in a text box. I tried casting to a date to a string, etc. All I get is:

Conversion from type 'DateTimeOffset' to type 'String' is not valid. ('String' is replaced by anything I try to cast it to)

Surely there must be a way to have a text box show "From 5/1/2013 to 5/31/2013" when the user types "5/1" and "5/31" in the date field? Does Microsoft really think computer-literate people want to pick up the mouse to use their date picker instead of using tab?

2 Answers 2

1

Try the following expression:

="From " & Format(Parameters!Param1.Value.DateTime, "M/d/yyyy") & " to ..... etc"

To test this expression I've created a fresh report, added a DateTime parameter, and entered "5/1" in the textbox, hit enter. The report comes up with the following textbox:

From 1/5/2013 to ..... etc

For my locale, this is correct, because when entering DateTime values days are assumed to come before months. When the report is viewed the textbox will also update and show:

5-1-2013 0:00:00 +01:00

From this you should be able to extrapolate and use it for a second parameter as well, extending the expression to show the exact string you need in your report.

2
  • Thanks Jeroen. I think I tried that, btu will try again tomorrow, just heading out. Regards Mark
    – mark1234
    May 28, 2013 at 22:02
  • no go, I'm afraid. I didn't notice the .DateTime until I tried, but that's not an available method in my BIDS all I have is Equals and ReferenceEquals. I'm using Vs2008 9.0.30729.4462.QFE
    – mark1234
    May 29, 2013 at 19:32
1

The Parameters!Param1.Value.DateTime helped when the user omits the year, but it broke down when the user decides to include the year. I couldn't get it to work under both conditions.

Try this.

Include the date parameter value as a field in your resultset. Your SQL might look like:

SELECT field1, field2, Convert(date, @FromDate) [FromDate_param] FROM table

Then you can create an expression in SSRS like:

 ="From " & Format(First(Fields!FromDate_param.Value), "M/d/yy")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.