AS400 Convert text date field in mm/dd/yyyy format and store as a date field

I need to check a 10 digit text field for a valid date, then store the date in a date type field. what's the best why to do this in rpg?
LVL 1
roosterupAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gary PattersonVP Technology / Senior Consultant Commented:
Use the %Date built in function.

myString = '01/31/1903';
myDate = %date (my String :  *usa);

Monitor for error.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
roosterupAuthor Commented:
I decided to use test(de) but I assume your solution would work.  any advice on the easiest way to test for future dates or ridiculously old dates?
Gary PattersonVP Technology / Senior Consultant Commented:
// To test for a future date:
if myDate > %date();
... do something here
endif;

// To test for a date prior to Jan 1, 1900, assuming DATFMT is set to ISO.
d riduculouslyOldDate...
d                                 c                       const(d'1900-01-01')
if myDate < ridiculouslyOldDate;
... do something here
endif;
tliottaCommented:
How "well formed" are the dates? I.e., will they always be MM/DD/YYYY? Or is "1/7/2015" valid?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
IBM System i

From novice to tech pro — start learning today.