RPGLE date conversion

2880 pts.
Tags:
RPGLE
Hey again, I have on my RPGLE display screen a date field (Numeric 8,0) which format is DDMMYYYY. But when I want to store it in the physical file. I want it to be in the format (*ISO YYYY-MM-DD). How can I convert from the DDMMYYYY format know the appropriate century? Can anyone help me in this issue?
1

Answer Wiki

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

Check out the IBM link on the CVTDAT command.

It lists all the possibilities and possible error messages you may get.

Discuss This Question: 10  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.
  • pdraebel
    You could use CL command CVTDAT. or check https://www.itjungle.com/2005/11/30/fhg113005-story01/
    7,545 pointsBadges:
    report
  • Splat
    Is the field in the file defined as a date field or as a numeric field?

    If the first, you can use [file date field] =  %date([display date field]: *EUR);

    If the second you can either use a data structure or try [file date field] =  %dec(%date([display date field]: *EUR)); (not sure if this would work or no, but it might be worth a try).
    12,895 pointsBadges:
    report
  • Subhendu Sen
    As you mentioned the date is in a ten byte character field as YYYY-MM-DD, the format can be %date(alpha_date : *iso). Also if you did not want dasheds (8 characters), just put 0 at the end of the format name. For your assistance, please link here: https://search400.techtarget.com/tip/RPG-free-format-date-conversion-cheat-sheet.
    140,150 pointsBadges:
    report
  • Sureyz
    Could we do something like this? But its not working.

    eval      iso_to = %dec(%date(tdt:*EUR):*CYMD)
    2,880 pointsBadges:
    report
  • Splat
    Sureyz, what are the attributes of iso_to?
    12,895 pointsBadges:
    report
  • Sureyz
    Sorry for the late reply..

    iso_to  defined in D spec with 10d DATFMT(*iso).
    2,880 pointsBadges:
    report
  • Splat
    If iso_to is a date field you don't want to use the %dec bif. Just use %date(tdt:*EUR) & make certain tdt is actually in the *EUR format. 
    12,895 pointsBadges:
    report
  • ToddN2000
    If you run this using debug, what date format are you getting back?
    133,595 pointsBadges:
    report
  • NickHutcheson1

    I use this program a lot to test results of date conversions.

    D Iso             S               D   datfmt(*ISO)                                     
    D Scr             S              8  0 inz(12312017)                                    
     *------------------                                                                   
    C                   EVAL      ISO = %DATE                                              
    C                   eval      iso = iso - %days(365)                                   
     *                                                                                     
                                  ISO = %date(SCR:*usa);      // mmddccyy  to  D'ccyy-mm-dd'
    c                   dsply                   Iso                                        
     *                                                                                     
    C                   SETON                                        LR                    

    DSPLY  2017-12-31

    So, the field ISO is correct.  The actual conversion works with either /Free or RPGIV Eval.  I have seen a couple of the conversions not liked by RPGIV.  I forget which though.

    1,485 pointsBadges:
    report
  • BigKat
    eval      iso_to = %dec(%date(tdt:*EUR):*CYMD) 
    *CYMD = CYYMMDD where C = 0->1900, 1->2000, 2->2100,... 
    *ISO = YYYYMMDD

    9,460 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:

To follow this tag...

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

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

Following

Share this item with your network: