Problem solve Get help with specific problems with your technologies, process and projects.

Using date data-type fields in RPG IV

Date data types are incredibly powerful and flexible, but figuring out how to use them to do date format conversions can be frustrating.

Date data types are incredibly powerful and flexible, but figuring out how to use them to do date format conversions...

can be frustrating because the examples in the manuals never seem to get to the meat of the issue and give you simple examples. The key to understanding how to do the conversions is to realize that the date data-type field is in ALL formats. You can put any date format into it and pull any date format out of it. Here are some real-world examples:

First define a work field as a date data type  

  D WorkDate        s               d

Use the work field as your conversion method by putting a date in one format into it and pulling out that date in another format. To convert *MDY to *ISO

  C     *MDY          Move      MDYDate       WorkDate  
  C     *ISO          Move      WorkDate      ISODate   

  *USA to *MDY 
  C     *USA          Move      USADate       WorkDate  
  C     *MDY          Move      WorkDate      MDYDate

Note that the work field doesn't need a date format defined, it's ALL formats. The formatting is required to tell what date format is going into the work field (first line) and what format you want to come out (second line). The data being moved into the work field must be a valid date in the format you specified or the program will crash, so it's a good idea to test the validity first.

  C     *USA          TestD     USADate                 70

*IN70 will be turned on if the date is not a valid date in *USA (MMDDYYYY) format.

You can even do date conversions from/to character fields to/from numeric fields, but remember that the character field must include the separators ('02/05/01') going into the conversion and be long enough to hold the separators coming out of the conversion.

This was last published in February 2001

Dig Deeper on RPG iSeries programming

Start the conversation

Send me notifications when other members comment.

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

Please create a username to comment.