TechTalk: Easy Date Conversion

CL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Have you ever needed to change the format of a date, for example, MMDDYY to YYMMDD? You can write a short subroutine to handle the task or you can use the CVTDAT command. With CVTDAT you can convert any supported date format to MMDDYY, DDMMYY, YYMMDD, the system date format, and Julian formats. The following command will convert a date in MMDDYY format to YYMMDD format:

 CVTDAT DATE(&DATE) + TOVAR(&NEWDAT) + FROMFMT(*MDY) + TOFMT(*YMD) + TOSEP(*NONE) Valid FROMFMT and TOFMT parameters are *JOB, *SYSVAL, *MDY, *DMY, *YMD, |TAG SYS|and *JUL. 

.

You can use CVTDAT in your RPG programs by passing the date to a CL program that runs CVTDAT and passes back the converted date.

The parameter TOSEP lets you specify the type of date separators you wish to use for the converted date. Valid parameters are *JOB, *SYSVAL, *NONE, or a separator character. Valid characters are "/", "-", ".", or ",".

A word of caution! If you use a separator, be sure your TOVAR variable is long enough to hold the date with the separator or your program will bomb. Example: TOVAR(&DATE) must be declared with a length of 8 if TOSEP is TOSEP(/).

Blake Mesenbrink Jonesboro, Arkansas

BLOG COMMENTS POWERED BY DISQUS