Tips and Techniques: Processing Dates

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

Date processing continues to be a pain in the neck for many RPG programmers. RPG III still does not support true date fields, while RPG IV and DDS do. Consequently, those who have not moved their entire set of applications to RPG IV have decided to not use date fields in their database files.

In V5R2, IBM added a date format code to the %CHAR built-in function that allows you to specify the resulting format of the date value that is generated.

In V5R3, IBM has added the capability to convert a numeric value into a date value and specify the format that the value is stored in. The %DATE built-in function now converts a numeric value into a date value. The second parameter of %DATE allows you to specify the format of the non-date value that you are converting. This allows you to compare or assign a non-date value to a true date variable.

Prior to V5R2, you had to use the MOVE operation code to convert the non-date value to a true date field and then use that field to compare.

While things are getting easier, it would still be beneficial if IBM would add true date data-type support to the RPG III language. But don't hold your breath.

The following are examples of the techniques explained above:

     D Today           S               D   Datfmt(*JUL)
     D DueDate2        S               D   Datfmt(*ISO)
     D dueDate         S              8S 0
      
      /IF DEFINED(*V5R3M0)
     C                   if        %Date(dueDate:*ISO) > Today
      /ELSEIF DEFINED(*V5R2M0)
     C                   if        %int(%Char(dueDate)) > 
     C                                %Int(%char(NewDate:*ISO0))
      /ELSE
     C     *ISO0         MOVE      dueDate       dueDate2
     C                   if        dueDate2 > Today
      /ENDIF

Bob Cozzi is a programmer/consultant, writer/author, and software developer of the RPG xTools, a popular add-on subprocedure library for RPG IV. His book The Modern RPG Language has been the most widely used RPG programming book for nearly two decades. Along with others, he speaks at and runs the highly popular RPG World, a conference for RPG programmers.

BOB COZZI

Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.


MC Press books written by Robert Cozzi available now on the MC Press Bookstore.

RPG TnT RPG TnT
Get this jam-packed resource of quick, easy-to-implement RPG tips!
List Price $65.00

Now On Sale

The Modern RPG IV Language The Modern RPG IV Language
Cozzi on everything RPG! What more could you want?
List Price $99.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: