Skip to Content
author's profile photo Former Member
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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.