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

Date Format on Variable Output

Status
Not open for further replies.

giggles7840

IS-IT--Management
Mar 8, 2002
219
US
CRXIR2SP2
Win Pro

I have a formula that generates a Date in a String Datatype.
This is the code:
whileprintingrecords;
stringvar array x := [totext({@00 Date}),totext({@01 Date}),totext({@02 Date}),
totext({@2A Date}),totext({@03 Date}),totext({@3A Date}),totext({@04 Date}),
totext({@05 Date}),totext({@06 Date}),totext({@07 Date}),totext({@08 Date}),
totext({@09 Date}),totext({@10 Date}),totext({@11 Date}),totext({@12 Date})];


stringvar array y;
numbervar cnt := 0;
numbervar i := 0;

for i := 1 to ubound(x) do(
if x <> "" then
(
cnt := cnt + 1;
if cnt <> 0 then (
redim preserve y[cnt];
y[cnt] := x)));
if cnt = 0 then
"" else
y[cnt]

The values that are spit out are correct and they look like this:
1/1/2007

However, now my customer wants to see the format as 01/01/2007

when I try to create a new formula to convert this formula using date(varformula) it tells me that it is a bad date format.

If I try to change the variable code to:
whileprintingrecords;
datetimevar array x := [datetime({@00 Date}),datetime({@01 Date}),datetime({@02 Date}),
datetime({@2A Date}),datetime({@03 Date}),datetime({@3A Date}),datetime({@04 Date}),
datetime({@05 Date}),datetime({@06 Date}),datetime({@07 Date}),datetime({@08 Date}),
datetime({@09 Date}),datetime({@10 Date}),datetime({@11 Date}),datetime({@12 Date})];


stringvar array y;
numbervar cnt := 0;
numbervar i := 0;

for i := 1 to ubound(x) do(
if x <> "" then
(
cnt := cnt + 1;
if cnt <> 0 then (
redim preserve y[cnt];
y[cnt] := x)));
if cnt = 0 then
"" else
y[cnt]

When I get to the line 'if x <> "" then ' I get a message that says 'A date-time is required'

Any ideas?
 
Try:
if ToText(x) <> "" then

-------------------------------------------------------------------------------------------------------------------------
"Now I can look at you in peace; I don't eat you any more." Franz Kafka, while admiring fish in an aquarium
 
Close......
At this line:
datetimevar array x :=
I now get the message:
A variable cannot be redeclared with a different type.
 
Make sure you don't have another formula where global variable x is declared with another data type.

-------------------------------------------------------------------------------------------------------------------------
"Now I can look at you in peace; I don't eat you any more." Franz Kafka, while admiring fish in an aquarium
 
If i change those new totext to datetime then i get
this line:
if datetime(x) <> "" then
says:
'A date is required here' on the x piece of the line.
 
It should be:
if ToText(x) <> "" then
because we compare with "" which is a string.

Make sure you did not keep the old formula where x was a stringvar array.

By default in Crystal a variable is global, so if you declare the same var as string in a formula, and datetime in another formula there will be an error.

-------------------------------------------------------------------------------------------------------------------------
"Now I can look at you in peace; I don't eat you any more." Franz Kafka, while admiring fish in an aquarium
 
No globals. All of them should be local.... Thats the default if you dont specify, right?
 
No, the default is global in Crystal, this is the problem.

-------------------------------------------------------------------------------------------------------------------------
"Now I can look at you in peace; I don't eat you any more." Franz Kafka, while admiring fish in an aquarium
 
sorry my message went out before i saw your global answer.

I will see what i can change.
 
I changed the name from x to date. that helped. However I still end up with a string datatype in the end and i still get a bad date format if i try to convert it in a formula using either date() or datetime(). :(
 
Maybe it's better to keep your first version with x stringvar array, and just format the result.

You obtained "1/1/2007" and you want "01/01/2007".

ToText(DateTime("1/1/2007"), "MM/dd/yyyy") will do the change.

-------------------------------------------------------------------------------------------------------------------------
"Now I can look at you in peace; I don't eat you any more." Franz Kafka, while admiring fish in an aquarium
 
Yes, I think I helped you with the original formula. Change the end of the orginal formula to read:

if cnt <> 0 then (
redim preserve y[cnt];
y[cnt] := x)));
if cnt = 0 then
date(0,0,0) else
date(y[cnt])

Then since the result is a date, you can just go to format field->date and set the format there.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top