Included within the new Technology Refreshes, IBM i 7.6 TR1 and IBM i 7.5 TR7, comes three new date formats to help us with the 2040 date problem. All of the new data formats include the century in the date:
- *DMYY: DD/MM/YYYY format
- *MDYY: MM/DD/YYYY format (isn't this the same as the *USA format?)
- *YYMD: YYYY/MM/DD format
These, like the other date formats, can be used with following Built in Functions, BiFs, and operation codes:
- %CHAR: Convert to character BiF
- %DEC: Convert to decimal number BiF
- %DATE: Convert character or decimal to date BiF
- MOVE and MOVEL: Move and move left operation codes
- TEST(D): Test date operation code
Let me give some examples of using these new data formats:
01 **free
02 dcl-s Today date inz(*job) ;
03 dsply ('*DMYY = ' + %char(Today : *DMYY)) ;
04 dsply ('*MDYY = ' + %char(Today : *MDYY)) ;
05 dsply ('*YYMD = ' + %char(Today : *YYMD)) ;
06 dsply ('*EUR = ' + %char(Today : *EUR)) ;
07 dsply ('*USA = ' + %char(Today : *USA)) ;
08 dsply ('*JIS = ' + %char(Today : *JIS)) ;
09 dsply ('*ISO = ' + %char(Today : *ISO)) ;
|
Line 2: The variable Today is a date and is initialized with the job's date. In this example the job's date is November 30, 2025.
Line 3: Use the Display operation code, DSPLY, to show the result of converting the value in the variable Today in a character value in *DMYY format.
Line 4: The same conversion to a character value in *MDYY format.
Line 5: Convert Today to *YYMD.
These formats can look similar to others. The next four lines convert the date to other formats.
Line 6: Convert the date to *EUR (European) format.
Line 7: Convert the date to *USA format.
Line 8: Convert to *JIS (Japanese Industrial Standard) format.
Line 9: Convert to (my favorite) *ISO format.
After compiling the program, and calling it, the following is displayed:
DSPLY *DMYY = 30/11/2025 DSPLY *MDYY = 11/30/2025 DSPLY *YYMD = 2025/11/30 DSPLY *EUR = 30.11.2025 DSPLY *USA = 11/30/2025 DSPLY *JIS = 2025-11-30 DSPLY *ISO = 2025-11-30 |
It is interesting to note that the *MDYY and *USA produce the same result.
*DMYY and *EUR only differ by the separator character. IMHO *DMYY is the best date format for the UK.
*YYMD, *JIS, and *ISO are all similar except for the separator character.
The formats show that we can use *DMYY in place of *DMY, *MDYY or *USA in place of *MDY, and *YYMD in place of *YMD.
In the next example I am going to take same date as before November 30 2025, validate it, and then convert it to another date format:
01 **free
02 dcl-s WorkChar char(10) ;
03 WorkChar = '11/30/2025' ;
04 test(de) *mdyy/ WorkChar ;
05 if (%error) ;
06 dsply ('TEST(DE) error for ' + WorkChar) ;
07 endif ;
08 WorkChar = %char(%date(WorkChar : *mdyy/) : *yymd) ;
09 dsply ('WorkChar = ' + WorkChar) ;
|
Line 2: The variable WorkChar has been defined as a ten long character variable.
Line 3: I move the "date" November 30 2025, in *MDYY format, into WorkChar.
Line 4: I validate that the "date" in WorkChar is a valid date in the *MDYY format with "/" as the separator character.
Lines 5 – 7: If the "date" is not valid I display a message stating that the date is not valid.
Line 8: I am converting the value in WorkChar to a real date using the %DATE BiF, giving that the value in WorkChar is in *MDYY format, with the slashes. Then the date is convert to character, using the %CHAR BiF, in *YYMD format. And the result replaces the contents in WorkChar.
Line 9: Display the contents of WorkChar.
After compiling the program was run, and the following was displayed:
DSPLY WorkChar = 2025/11/30 |
These new date format codes are useful additions. What I like most is I can now format dates for the UK without have to replace the separator characters in the output from the *EUR.
You can learn more about the new date formats in RPG from the IBM website here.
This article was written for IBM i 7.6 TR1 and 7.5 TR7.




No comments:
Post a Comment
To prevent "comment spam" all comments are moderated.
Learn about this website's comments policy here.
Some people have reported that they cannot post a comment using certain computers and browsers. If this is you feel free to use the Contact Form to send me the comment and I will post it for you, please include the title of the post so I know which one to post the comment to.