My stored procedure accepts either a datetime (e.g. 12/3/13) or an integer indicating how many days previous to today (e.g. today, 2 would equate to 12/3/13). The sp converts an integer to a date in this manner:
ifisnumeric(@firstday)= 1 set @startdate=DATEADD(dd,datediff(dd,convert(int,@firstday),getdate()),0)
elseset @startdate =
CONVERT(datetime,@firstday)
where @firstday is a varchar(20) and @startdate is the datevalue I use for my query.
I need some way to display the date on my report though. If the user types 12/3/2013 I want to display that, but if he types 2, then I want to still display 12/3/2013. Since the sp does not need SSRS to do any manipulation of the data, I decided
to use an internal parameter (data type Text) for display purposes.
This will execute but is not what I want--
=iif(isdate(Parameters!firstday.Label),Parameters!firstday.Label,Parameters!firstday.Label)
This executes for 12/3/13 but not for an integer--
=iif(isdate(Parameters!firstday.Label),FormatDateTime(Parameters!firstday.Label.ToString,DateFormat.ShortDate),Parameters!firstday.Label)
I get "An error occurred during local report processing. firstdayDatetime" (which is my internal parameter) whenever I use an integer.
I am at a loss as to why I can format "12/3/13" as a datetime ("12/3/2013") but when I simply try to display the "2" as a value, I get an error. I have also tried the dateadd logic I have above from my sp, but I continue
to get error messages.
Any thoughts including suggesting an entirely different approach are appreciated.