 Former Member

# Another date issue

I have a field that is numeric that can be 6 or 5 long. It is a date field

example 100788 = 10/07/1988 or

90592 = 9/05/92

I have the following conversion code in my report;

stringvar a:=(ltrim(rtrim(totext({PEMS.HIRED_DATE},0,''))));

numbervar m;

numbervar d;

numbervar y;

if length(a)=6 then

(

m:= tonumber (a [1 to 2]);

d:= tonumber (a [3 to 4]);

y:= tonumber (a [5 to 6]);

)

else

m:=tonumber (a [1 to 1]);

d:=tonumber (a [2 to 3]);

y:=tonumber (a [4 to 5]);

date(y,m,d)

I get a value orf 100788 and the program kicks out saying day cannot be between 0 and the number of days in a month. The variables displayed are :

PEMS.HIRED.DATE = 100788

A "100788"

M 10

D 0

Y 78

Since this is a 6 length I gather it should go through the 6 length calculation. However it appears to be going through the 5 length and I cannot see why.

Any help would be appricated...

Jim

10|10000 characters needed characters exceeded

### Related questions Former Member
Posted on Oct 30, 2008 at 07:52 PM

Try this formula

```stringvar a:=(ltrim(rtrim(totext({PEMS.HIRED_DATE},0,''))));

numbervar m;
numbervar d;
numbervar y;

if length(a)=6 then
(
m:= tonumber (a [1 to 2]);
d:= tonumber (a [3 to 4]);
y:= tonumber (a [5 to 6]);
)

else
(
m:=tonumber (a [1 to 1]);
d:=tonumber (a [2 to 3]);
y:=tonumber (a [4 to 5]);
);
date(y,m,d)```

Regards,

Raghavendra

10|10000 characters needed characters exceeded
• Former Member
Posted on Oct 30, 2008 at 08:20 PM

Hi James,

Try the following :

```stringvar a:=(ltrim(rtrim(totext("010599"))));

stringvar m;
stringvar d;
stringvar y;

if length(a)=6 then
(
m:=  left(a,2);
d:=  mid(a,3,2);
y:=  mid(a,5,2);
)

else
(
m:=  left(a,1);
d:=  mid(a,3,2);
y:=  mid(a,5,2);
);
date(tonumber(y),tonumber(m),tonumber(d))
```

Thanks,

Sastry

Edited by: Sastry Duvvuri on Oct 30, 2008 9:43 PM