• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Date and Time Functions in V5R1 RPG

    August 9, 2002 Timothy Prickett Morgan

    Hey, Ted:

    Here’s a snippet of RPG code that loads timestamp variables from legacy date formats and date/time variables.

    It shows how to use three new built-in functions to make date/time comparisons easier than they used to be.

    The problem arises when dates and times are stored in separate fields and must be compared.

    Maybe the dates and times are in fields of the date and time data types, but in many databases, they’re stored in plain old alpha or numeric fields.

    To compare two date/time combinations requires logic like the following example:

    * is job-on date/time before scheduled date/time?
    C                   if        (job_on_date < sched_date) or 
    C                             (job_on_date = sched_date and 
    C                              job_on_time < sched_time)    
    

    This is cumbersome, and I have seen many places where the comparison was done incorrectly.

    I convert all date and time pairs to timestamps before comparison. The %date, %time, and %timestamp built-in functions, introduced in V5R1, simplify such conversions.

    Use this code to convert a legacy date and time to a timestamp:

    H DATFMT(*ISO)   TIMFMT(*ISO)
    D legacy_time     s              6p 0 inz(073403)
     * HH MM SS
    D legacy_date     s              6p 0 inz(071802)
     * MM DD YY
    D legacy_stamp    s               z   inz
    /free
     legacy_stamp = %timestamp(
         %char(%date(legacy_date:*MDY)) + '-' +
         %char(%time(legacy_time:*hms)) + '.000000');
    /end-free
    

    Use this code to convert date and time data types to a timestamp:

    H DATFMT(*ISO)   TIMFMT(*ISO)
    D defined_time    s               t   inz
    D defined_date    s               d   inz
    D defined_stamp   s               z   inz
     /free
      defined_stamp = %timestamp(
           %char(defined_date) + '-' +
           %char(defined_time) + '.000000');
     /end-free
    

    — Craig Rutledge, www.jcrcmds.com

    Sponsored By
    COMMON

    REGISTER FOR COMMON IN DENVER, OCT. 13-17

    Get the IT training you need by attending COMMON Users Group’s Fall 2002 IT Education Conference & Expo, October 13-17 in Denver. Early Bird registration is $1,150 until September 4.

    Choose from over 720 sessions and labs covering a wide range of industry topics. Also receive training from J.D. Edwards, MAPICS, and other vendors.

    Don’t miss out! Go to www.common.org

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: mgo_rc, Volume 2, Number 60 -- August 9, 2002

    Sponsored by
    OCEAN User Group

    OCEAN TechCon25 Online

    It’s an Exciting Time for IBM i !

    July 16 & 17, 2025 – ONLINE

    Two virtual days of learning, presented by an outstanding group of IBM’ers and IBM Champions, featuring leading-edge topics.

    FREE for OCEAN members!

    Register NOW!

    Annual (12-month) Individual OCEAN Memberships are $80 and a Corporate Membership is $250. A Corporate Membership would allow your entire company to have full access to the OCEAN website & video library and to attend OCEAN events at member rates. Act now because rates are increasing on August 1, 2025.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tell PC5250 to Stop Bugging Me about My Password Using Timestamps as Unique Keys

    Leave a Reply Cancel reply

MGO Volume: 2 Issue: 60

This Issue Sponsored By

    Table of Contents

    • TCP/IP Printing Problem
    • Default Connection for CAE Users
    • Date and Time Functions in V5R1 RPG

    Content archive

    • The Four Hundred
    • Four Hundred Stuff
    • Four Hundred Guru

    Recent Posts

    • With Power11, Power Systems “Go To Eleven”
    • With Subscription Price, IBM i P20 And P30 Tiers Get Bigger Bundles
    • Izzi Buys CNX, Eyes Valence Port To System Z
    • IBM i Shops “Attacking” Security Concerns, Study Shows
    • IBM i PTF Guide, Volume 27, Number 26
    • Liam Allan Shares What’s Coming Next With Code For IBM i
    • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
    • VS Code Will Be The Heart Of The Modern IBM i Platform
    • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
    • IBM i PTF Guide, Volume 27, Number 25

    Subscribe

    To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

    Pages

    • About Us
    • Contact
    • Contributors
    • Four Hundred Monitor
    • IBM i PTF Guide
    • Media Kit
    • Subscribe

    Search

    Copyright © 2025 IT Jungle