Oops, for the second example, I meant this:
Main Topics
Browse All TopicsI am in need of a a query deifnition in the AS/400 Define Results Fields that will format an existing field to a date format. The existing field has data representing an activity date and appears as 20,090,417 which I would like to convert in the report output as 04/17/2009.
The expression I used yeilds nothing but + signs in the ouput.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
First you have to use DIGITS to convert the numeric to character, then you can use substring to parse out the date components, and finally use the concatenation operator to stick it all back together with slashes inthe right places.
substring(digits(mm
If you can live with yyyy/mm/dd format,. just use an edit word in the report column formatting ('bbbb/bb/bb') (b=blank) instead of all of this.
- Gary Patterson
If you are dumping to an output file, the best way to make sure dates convert properly isto conver to DATE data type. In query/400 this means that you have to take you numeric date, convert it into job date format (DSPJOB to see your job date format), then wrap that converted character date in the DATE function:
Assuming *MDY job date format with a job date separator of "/":
date(substring(digits(
- Gary Patterson
Thanks
the problem is now on the output of that field when the query is run...the below error message appears and I think it is related to zero value on some of the items in the MYDATE field
ERROR
Column MYDATE contains replacement character +.
OUTPUT
MYDATE LAST ACT
++++++++ 0
03/15/05 20,050,315
08/05/04 20,040,805
02/25/06 20,060,225
++++++++ 0
++++++++ 0
++++++++ 0
++++++++ 0
++++++++ 0
Yeah, 00/00/0000 is not a valid date. Date fields must contain a valid date. Query/400 isn't equipped to deal with this.
Either fix your data to contain valid dates, or you can create an SQL view that uses the following logic:
CREATE VIEW mylib/myview AS
SELECT (columns),
CASE WHEN mmdtac=0 THEN date('01/01/0001')
ELSE date(substring(char(mmdtac
right(char(mmdtac,2) || '/' ||
left(char(mmdtac),4))
END AS mmdtac2
FROM MYLIB/MYFILE
Then, if you absolutely must use Query/400, you can use the view you created, and it will have valid dates in the MMDTAC2 column.
- Gary Patterson
Hey Guys, thanks for your help on this, however, because of SOX, I do not have access to the UDF so I will need to turn over to our programming group. I was able to dump the raw data into Excel and clean up the date issue much more easily. This will have to work for meantime. But many of your other insights will come in handy down the road on other queries.
KALULAX
Business Accounts
Answer for Membership
by: daveslashPosted on 2009-04-17 at 12:59:01ID: 24171525
It's been several years since I last used WrkQry, but this would be SIGNIFICANTLY easier using SQL.
e.g.
Select allOpen in new window