1

I'm a bit of an SSRS newbie and I'm having some trouble converting an Int to a Date in SSRS. The publication_date.Value is fed from a proprietary database as an Int type (so we unfortunately have no control over that) in the format 20160519.

The following works splendidly when there is a value present:

=CDate(Left(Fields!publication_date.Value, 4) + "-" + Mid(Fields!publication_date.Value, 5, 2) + "-" + Right(Fields!publication_date.Value, 2))

However, when there is a null it returns an #Error, which I'd like to suppress. I've tried using an IIf statement but without success.

=Iif(Fields!publication_date.Value is nothing,"", CDate(Left(Fields!publication_date.Value, 4) + "-" + Mid(Fields!publication_date.Value, 5, 2) + "-" + Right(Fields!publication_date.Value, 2)))

I've been digging around for other solutions but yet to find anything that works. Please help!

Edited - thanks for the duplicate article suggestion, however I need to convert an Int to a Date and handle the errors, not a Date to an Int.

Pedram
  • 6,256
  • 10
  • 65
  • 87

1 Answers1

0

I had the same issue,

As per your example, do one thing.

Keep you expression same like below,

=CDate(Left(Fields!publication_date.Value, 4) + "-" + Mid(Fields!publication_date.Value, 5, 2) + "-" + Right(Fields!publication_date.Value, 2))

Now, tricky part would be, in textbox visibility use below expression.

=IIf(IsNothing(Fields!publication_date.Value),True,False)

It will definitely work. Let me know if you face any issue. Thanks.

Pedram
  • 6,256
  • 10
  • 65
  • 87