Tip

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 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 first published in February 2001

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

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
Sort by: OldestNewest

Forgot Password?

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

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.