Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Parsing string to get date Post Reply Post New Topic
Author Message
slackerchris
Newbie
Newbie
Avatar

Joined: 20 Jan 2012
Location: United States
Online Status: Offline
Posts: 1
Quote slackerchris Replybullet Topic: Parsing string to get date
    Posted: 20 Jan 2012 at 9:20am
So im kind of a noob and need some help here. im looking to parse a column that is a string value.

the value is as follows:
"Return in about 8 weeks (around 4/1/2010)."

They are all a little different in length ether the number or it could be weeks, month(s) or year(s) but it's always in the same format. I am trying to get the date, any thoughts?
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 23 Jan 2012 at 7:16am

If the "/" character is used in the date ONLY (never used for anything else in the field) and the date is always followed by ")", you could create a formula something like this:

NumberVar i := 0;
Numbervar start := 0;
StringVar data;
i := InStr({table.field}, '/');
start := InStrRev({table.field}, '/', i);
data := right({table.field}, length({table.field}) - start);
i := InStr(data, ")";
left(data, i-1)
 
Note that there is no semi-colon at the end of the last line - this is important!
 
This returns the date as a string.  If you need it as a date, you'll need to parse the string into day, month, and year and use the DATE() function to conver it.
 
-Dell
 


Edited by hilfy - 23 Jan 2012 at 7:19am
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.031 seconds.