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

Function ???

Status
Not open for further replies.

pungigi

Programmer
Oct 29, 2003
115
US
I have a field "APTDT" in my database that was set up as a string and the return is 20041122.

I have the following Function to turn it into a date so I can use the "in the period of" acctg options in Crystal.

Function (numberVar v2)
local stringvar str;
str:=totext(v2,0,"");
local stringvar dd:=right(str,2);
local stringvar mm:=mid(str,5,2);
local stringvar yy:=left(str,4);

date(tonumber(yy),tonumber(mm),tonumber(dd));

Whenever I try to run the report I get the following error:

The string is non numeric.
date(tonumber(yy),tonumber(mm),tonumber(dd));

The middle \tonumber(mm)\ is highlighted, can anyone help.

 
You should try using a formula field, first test isnull and then use DateValue to convert it to a date.

It helps to give your Crystal version, since newer versions have extra options, and some extra problems. I use Crystal 8.5.

[yinyang] Madawc Williams (East Anglia, UK) [yinyang]
 
Assumming this field is alway test ina YYYYMMDD Format, the following formula is much cleaner:

[red]NumberToDate(Val({YourTextField}))[/red]

Test for nulls first as Mcoleman and Madawc suggested.

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
askdon@srhconsulting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top