Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Formula to Convert Date to Arbitrary String? Post Reply Post New Topic
Author Message
spiranthes
Newbie
Newbie


Joined: 13 May 2011
Online Status: Offline
Posts: 2
Quote spiranthes Replybullet Topic: Formula to Convert Date to Arbitrary String?
     Posted: 13 May 2011 at 9:17am
Hello,
 
I am using Crystal Reports XI and have a table with a Date Time field.
 
I have inserted the field into my report but, wherever the field returns a certain date, I would like to change that date into an arbitrary non-date string.
 
For example: if DateTime field X = 05/01/1989 0:00 then I would like to see 00/00/00 in the report.
 
I am trying variations of the following formula:
 
stringvar X = ToText({DateTime Field X}, "MM/dd/yy")
if stringvar = "05/01/89"
then stringvar = "00/00/00"
 
However, I run into two problems. First, Crystal Reports tells me that everything beyond the first line of the formula does "not appear to be part of the formula." Secondly, I can't figure out how do I get stringvar to appear in the report.
 
Any help with this vexing problem would be very much appreciated!
IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 13 May 2011 at 10:05am
Assignments in crystal syntax are done using := and you have to put a semi-colon at the end of the line. I am assuming you are using crystal syntax.

I'm assuming you meant

If x = "05/01/80"

The value displayed by the formula is the value that it returns.

So at the end just type "x" or whatever the variable is and it should display it.

Edited by Keikoku - 13 May 2011 at 10:06am
IP IP Logged
spiranthes
Newbie
Newbie


Joined: 13 May 2011
Online Status: Offline
Posts: 2
Quote spiranthes Replybullet Posted: 13 May 2011 at 12:59pm

Thank you Keikoku for setting me off down the right path.

This is the formula that worked:
 
stringvar X := "00/00/00";
if ToText({Table.DateTimeField}, "MM/dd/yy") <> "01/01/53" then ToText({Table.DateTimeField}, "MM/dd/yy") else X
 
Kind regards.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum