Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error in Formula

Status
Not open for further replies.

psmani

Programmer
Joined
Sep 27, 2001
Messages
2
Location
GB
Hi,
I have one more problem in accessing crystal reports, when i try to access a crystal report its giving me a runtime error saying that "Bad date format string" in one formula. Actually in that formula the following code is written

if not isnull({@rMajDateOfPrice}) then
if Year (Date({@rMajDateOfPrice})) = 1941 then
1
else
0

rMajDateOfPrice is actually a nvarchar field in database, thats the reason i am converting to date and then getting the year

Any suggestions for this.....

Thanks in advance

Regards
Manikandan
 
The Date() function usually returns the currect date. To convert a string type to a date type use the CDate() function. Try,


if not isnull({@rMajDateOfPrice}) then
if Year (CDate({@rMajDateOfPrice})) = 1941 then
1
else



Thanks and Good Luck!

zemp
 
You are showing a formula {@rMajDateOfPrice} not the field {rMajDateOfPrice} in your formula above. So what is in your formula {@rMajDateOfPrice}?

-LB
 
zemp: You're mistaken, date returns the same as cdate and datevalue.

LB is correct, you're not using a database field, you're using a formula.

It might be simpler to not worry over converting to a date, and just pull the value you need from the string, as in:

val(left({rMajDateOfPrice},4))

I try to use SQL Expressions to handle this sort of thing as then the work is offloaded to the database.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top