Learn how to a build a cloud-first strategyRegister Now

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

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
Asked:
jheg
  • 5
  • 2
1 Solution
 
mlmccCommented:
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
 
mlmccCommented:
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
 
mlmccCommented:
You don't need the ubound line so delete it.

mlmcc
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
frodomanCommented:
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
 
mlmccCommented:
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
 
frodomanCommented:
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
 
mlmccCommented:
You are probably correct.  I forgot you were specifying the format string.

mlmcc
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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