Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: something wrong with this date formula.. Post Reply Post New Topic
Author Message
celticpiping
Newbie
Newbie
Avatar

Joined: 25 Oct 2007
Online Status: Offline
Posts: 24
Quote celticpiping Replybullet Topic: something wrong with this date formula..
     Posted: 27 Aug 2012 at 6:37am
I'm pretty new to formulas in crysatl:
Have a date string in this format on a report field:
20120101
I'd like to simply convert that to 2012/01/01, or yyyy/mm/dd

I'm trying to use:

StringVar DT := '{Command.STUDY_DATE}'
Date (
Val (DT [  1 to  4 ]),
Val (DT [  5 to  6 ]),
Val (DT [  7 to  8 ]) )

The date value is obtained by means of a command.

When I run in formula workshop, it tells me:
"The remaining text does not appear to be part of the formula"


Thoughts?
Rich
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 27 Aug 2012 at 6:55am
if {Command.STUDY_DATE} is actually a string then
StringVar DT := {Command.STUDY_DATE};
left(DT,4)+"/"+mid(DT,5,2)+right(DT,2)

If {Command.STUDY_DATE} is a number or a date (does not look like one), then it will first need to be converted to a string.

I hope this helps.
IP IP Logged
celticpiping
Newbie
Newbie
Avatar

Joined: 25 Oct 2007
Online Status: Offline
Posts: 24
Quote celticpiping Replybullet Posted: 27 Aug 2012 at 7:19am
just added in another "+" and it looks good!
thanks!!!!!!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 27 Aug 2012 at 8:04am
FYI - I believe you could have used your original formula with a semicolon added on the first line...
 
StringVar DT := '{Command.STUDY_DATE}';
Date (
Val (DT [  1 to  4 ]),
Val (DT [  5 to  6 ]),
Val (DT [  7 to  8 ]) )
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 27 Aug 2012 at 8:59am
I was not sure if the StringVar DT := '{Command.STUDY_DATE}' would convert to a string.  I thought DT would have the value {Command.STUDY_DATE} not the value of {Command.STUDY_DATE}.
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