Solved

# Date Conversion in Crystal Reports URGENT

Posted on 2007-10-04
618 Views
Have a string that needs to be converted to a date.

string = 200,710 needs to be converted to date an look like this Oct 2007
0
Question by:jheg

LVL 100

Expert Comment

You can use a formula like this

StringVar strYear := Left({YourStringDate},4);
StringVar strmonth := Right({YourStringDate},2);
StringVar Array strMonthNames[12] := ["Jan',"Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];

strMonthNames[Val(strmonth)] & " " & strYear

mlmcc
I
0

LVL 100

Expert Comment

Minor error in the above

Try this one

StringVar strYear := Left({YourStringDate},4);
StringVar strmonth := Right({YourStringDate},2);
StringVar Array strMonthNames;
strMonthNames := split("Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec",',');
ubound(strMonthNames);
strMonthNames[Val(strmonth)] & " " & strYear

Does the string include the comma?

if so try this minor modification
StringVar newString := Replace({YourStringDate},',','');
StringVar strYear := Left(newString ,4);
StringVar strmonth := Right(newString ,2);
StringVar Array strMonthNames;
strMonthNames := split("Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec",',');
ubound(strMonthNames);
strMonthNames[Val(strmonth)] & " " & strYear

mlmcc
0

LVL 100

Expert Comment

You don't need the ubound line so delete it.

mlmcc
0

LVL 42

Accepted Solution

mlmcc's formula will work, but in this case there is a much simpler formula using the built in "monthname" function:

numberVar x := cdbl({YourStringDate});
MonthName(x mod 100, true) + ' ' + totext(int(x / 100),'#');

frodoman
0

LVL 100

Expert Comment

One minor mod to frodoman's - Need to eliminate the , in the year.

numberVar x := cdbl({YourStringDate});
MonthName(x mod 100, true) + ' ' + totext(int(x / 100),'#','');

mlmcc
0

LVL 42

Expert Comment

Actually my formula won't have the comma in the year.  The single # in the format won't display commas in the numeric values.  At least it doesn't on my system - unless there's a regional settings difference...

frodoman
0

LVL 100

Expert Comment

You are probably correct.  I forgot you were specifying the format string.

mlmcc
0

## Featured Post

### Suggested Solutions

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.