Learn how to a build a cloud-first strategyRegister Now

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 662

# Date Conversion in Crystal Reports URGENT

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
jheg
• 5
• 2
1 Solution

Commented:
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

Commented:
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

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

mlmcc
0

Commented:
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

Commented:
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

Commented:
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

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

mlmcc
0

## Featured Post

• 5
• 2
Tackle projects and never again get stuck behind a technical roadblock.