Search code examples
datetimereporting-servicesssrs-expressiondatetime-parsing

SSRS Parse Date Error in SSRS Expression


Any idea why getting an #Error using the code below when the field fp_firstshifttimein does not contain value. But when the field contains value, it works.

=IIF(IsDate(Fields!fp_firstshifttimein.Value), 
DateTime.Parse(Fields!fp_firstshifttimein.Value).addDays(8), Nothing)

Same issue with the code below:

=IIF(IsNothing(Fields!fp_firstshifttimein.Value), Nothing,
 DateTime.Parse(Fields!fp_firstshifttimein.Value).addDays(8))

Thanks all.


Solution

  • I found out that SSRS evaluates each part of the function before the report is executed. I tried the code below. It worked.

    =IIF(IsDate(Fields!fp_firstshifttimein.Value),
    DateTime.Parse(iif(IsDate(Fields!fp_firstshifttimein.Value) ="1",
    Fields!fp_firstshifttimein.Value,"01/01/1900")).addDays(8), nothing)