Tuesday, February 14, 2012

Converting String to Date in Report Expressions

Hello,

I am running a report in RS 2005 and as an expression I have something like that:

=DateDiff("YYYY", NOW(), CDATE("2001"))

Unfortunately, I am getting message:

Conversion from string "2001" to type 'Date' is not valid.

Is there a way to fix it?

Thanks!

The CDATE function wants a valid date format passed to it and not just the year. It would work if you specified something like "1/1/2001" or "Jan 1, 2006". However, it appears all you're trying to do is find the difference between the current year and some specified year. If that's the case, I would suggest using the following expression instead:

=Year(Now()) - 2001

or if the specified year is a string value:

=Year(Now()) - CInt("2001")

Sincerely,

Micheal

|||

Greate advice!

Thanks for your help!

No comments:

Post a Comment