How to convert a Date given in Char format to numeric format in RPG of AS/400.

140 pts.
Tags:
AS/400
RPG
RPG/400
How do I convert a Date given in Char format to numeric format in RPG of AS/400?

Answer Wiki

Thanks. We'll let you know when a new response is added.

EVAL numericField = %dec(%date(alphaDate:*MDY/):*MDY)

The parm following the char field must be the format of the char field (I used *MDY with “/”for an example).

The parm at the end of the expression must be the format of the numeric field.
So this example converts 11/22/2008 to 11222008.

If you want 2008-11-22 converted to 20081122 make both parms *ISO.

Give an example of what you want and we can be more specific.

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    Why would you convert to Numeric? If it's a date, then convert to a Date data type instead. (I can guess at least one answer -- "Because the file doesn't define it as a Date. Instead it defines it as Numeric." Sigh.) Tom
    125,585 pointsBadges:
    report
  • Splat
    This from a program that updates a (software vendor's) file:
    YYYY   = %SubDt(%Date(InDate: *ISO0): *Years); 
    MM     = %SubDt(%Date(InDate: *ISO0): *Months);
    DD     = %SubDt(%Date(InDate: *ISO0): *Days); 
    The InDate field is character information coming from a fixed format .txt file.
    8,500 pointsBadges:
    report
  • BillJohnson76240
    I need to convert As-400 date 05/12/15  to MAPICS date 1150512
    25 pointsBadges:
    report
  • philpl1jb

    In RPGLE from a date type field

    1. assumes all dates are 21th century

    wrkdate7c = 1000000 + %dec( wrkdate : *YMD);

    2. or better solution is:

    wrkdate7c = %dec( wrkdate : *ISO) - 19000000;

    52,730 pointsBadges:
    report
  • Brijesh
    Here is similar discussion convert char to numeric.
    13,650 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following