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

AS400 string to date

Status
Not open for further replies.

ericfmyers

Technical User
Oct 30, 2008
10
US
I'm pulling dates from an AS400 database but when I try to use the CDate formula it's not returning the correct results.
For example, the field contains the value:

1080914

This formula:

CDate({TRH00.TXDATE})

returns the date 6/9/4859 which is wrong.

The correct date should be 9/14/2008.

Thank you for any help you can give.
 
Try:

stringvar x := {table.stringdate};
date(1900+val(left(x,3)),val(mid(x,4,2)),val(right(x,2)));

-LB
 
I tried that and then it was asking for a string then I realized that this is a number field. So in the formula I converted the field to a string then I added your code under it but now I'm getting the error:
"A month number must be between 1 and 12"

So then I tried:

numbervar x := {TRH00.TXDATE};
date(1900+val(left(x,3)),val(mid(x,4,2)),val(right(x,2)));

It now wants a string in place of the second line's X's.
 
Use:

stringvar x := totext({table.numberdate},0,"");
date(1900+val(left(x,3)),val(mid(x,4,2)),val(right(x,2)));

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top