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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracta date from a string 1

Status
Not open for further replies.

Debug44

Technical User
Jan 12, 2004
19
US
I am using Crystal 10.0.5 writing a report on a SQL data table.
I have the below string that I need to extract the date and time. The information in the field is as below.

CN=Bart Preston/OU=Waco/O=WEB01/07/2004 11:28:26 PMcel_2

The date time is always preceded by the words WEB or AFS and followed by cel_#

Any help would be greatly appreciated…
(This one has driven me nuts as I thought it would be easy, yet…..)

Thanks in advance

Bart
 
Try:

whileprintingrecords;
stringvar MyDate := {table.field}; //your field here
numbervar start:=0;
datetimevar OutDate; := cdate(1970,2,2)
if instr(MyDate,"WEB") > 0 then
start := instr(MyDate,"WEB")+3
else
if instr(MyDate,"AFS") > 0 then
start := instr(MyDate,"AFS")+3;
If Start > 0 then
Outdate := cdatetime(mid(MyDate,Start,22));
Outdate

Now it will show 1/1/1970 if your string doesnot have a date, otherwise the date.

-k
 
I think you could use:

mid({table.field}, instr({table.field},"WEB")+3,19)

...if the date is always formatted the same way.

-LB
 
You could, and if it is never blank, and you don't want to key off of a default, of course you also need the other criteria "AFS" as well, soan if would be in there.

I intentionally tried to supply what I would do, thorough beast I tend to be.

-k
 
Thanks so much to the both of you...and yes the field is never blank...so I went with:

if instr({unit.sqlKey},"WEB") >0 then
mid({unit.sqlKey}, instr({unit.sqlKey},"WEB")+3,22) else
mid({unit.sqlKey}, instr({unit.sqlKey},"AFS")+3,22)

(Changed it to the 22 to capture AM-PM)

It appears to be working fine...
Thanks again...

Bart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top