• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Ken Likes FMTDATE

    December 2, 2009 Hey, Ted

    I immediately loaded and tested your FMTDATE function when I saw it in Four Hundred Guru. I just wanted to say “Thank You!” The tool is fantastic! We have mostly ISO and LONGJUL dates in our files and it is always a pain when converting or throwing math at them. No more!

    Here is an example of some date math I tried on a LONGJUL order date and an ISO invoice date to calculate “Days-To-Ship” using your function:

    SELECT fmtdate(OrderDate, 'LONGJUL', 'ISO-') Ordered,
           fmtdate(InvDate, 'ISO', 'ISO-') Invoiced,
           Date(fmtdate(InvDate, 'ISO', 'ISO-'))-
           Date(fmtdate(OrderDate, 'LONGJUL', 'ISO-'))
      FROM ORDERS
    

    –Ken

    I got a good bit of positive response to my Format Date (FMTDATE) function. I’ve enjoyed using the function in my work, and evidently other readers have, too.

    Ken’s use of FMTDATE to simplify date arithmetic is good, but it’s got a tiny error in it that I want to correct. Subtracting one date from another yields a date duration, which can be misleading. Here’s Ken’s query over some test data I created.

    ORDERED     INVOICED    Numeric Expression
    2008-12-31  2009-01-15              15    
    2009-01-01  2009-03-31             230    
    

    There are not 230 days between January 1 and March 31. The value 230 means two months and 30 days. I have discussed date durations before.

    To make this work, use the DAYS function to create each date to a number that represents the number of days since January 1 of the year 1 A.D.

    SELECT fmtdate(OrderDate, 'LONGJUL', 'ISO-') Ordered,   
           fmtdate(InvDate, 'ISO', 'ISO-') Invoiced,        
           days(Date(fmtdate(InvDate, 'ISO', 'ISO-')))-     
           days(Date(fmtdate(OrderDate, 'LONGJUL', 'ISO-')))
      FROM Orders
    

    Here are the results of using the DAYS function.

    ORDERED     INVOICED    Numeric Expression
    2008-12-31  2009-01-15                15  
    2009-01-01  2009-03-31                89  
    

    This makes more sense to me, anyway. I’ve never thought that it was a good idea to show date durations to end users.

    –Ted

    Ken had one more question. . .

    Hey, Ted:

    When invoking FMTDATE from RPG, I am getting an error due to the number of parameters being invalid. I see that it’s because the service program expects five parameters to be passed. Correct me if I’m wrong, but I can only assume that SQL is more forgiving when invoking a function with un-sent trailing parameters, because I’m only passing three on the function call.

    With this in mind, I tweaked your code (sorry) to specify options(*nopass) for the last two parameters and recreated module, service program, and function. This took care of my RPG invocation of the service program, but I notice that now an SQL visit to the function returns no nulls as it nicely did before. I could have two versions of FMTDATE–one to create the service program for RPG without the last two parms, and one WITH the parms. I could use the latter to create the function and keep the NULL return capability for SQL, and the former for use in RPG programs without having to add the last two parameters. Do you agree?

    –Ken

    It is possible to invoke FMTDATE from RPG. After all, it’s a service program. Here’s how it’s done.

    H option(*srcstmt: *nodebugio)
    
    D FmtDate         pr            10a   varying
    D   inDate                       8p 0 const
    D   inFromFmt                    8a   varying const
    D   inToFmt                      8a   varying const
    D   inNullArray                  6a   const
    D   ouNull                       5i 0
    
    D ShipDate        s              7p 0
    D ShipDateP       s             10a
    D ShipDateNull    s              5i 0
    
     /free
         *inlr = *on;
         ShipDateP = FmtDate(ShipDate: 'cymd': 'mdyy/': *blanks: ShipDateNull);
         return;
    

    But there’s no need to go to all that trouble, Ken. I recommend you use the built-in functions that come with RPG instead of FMTDATE.

    monitor;
       ShipDateP = %char(%date(ShipDate:*cymd):*usa);
    on-error;
       ShipDateNull = -1;  // or whatever else you might want to do
    endmon;
    

    I’m glad that Ken and others found FMTDATE helpful.

    –Ted

    RELATED STORIES

    Formatting Dates with SQL

    Query and Date Durations



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Profound Logic Software:  FREE OnDemand Webinar. Learn how to easily build and extend i apps
    LANSA:  Take your apps to a new dimension with RAMP. FREE Webinar!
    Manta Technologies:  Your complete source for IBM i training

    IT Jungle Store Top Book Picks

    Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
    The iSeries Express Web Implementer's Guide: List Price, $49.95
    The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
    The System i Pocket RPG & RPG IV Guide: List Price, $69.95
    The iSeries Pocket Database Guide: List Price, $59.00
    The iSeries Pocket SQL Guide: List Price, $59.00
    The iSeries Pocket Query Guide: List Price, $49.00
    The iSeries Pocket WebFacing Primer: List Price, $39.00
    Migrating to WebSphere Express for iSeries: List Price, $49.00
    Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
    Getting Started with WebSphere Express for iSeries: List Price, $49.00
    Can the AS/400 Survive IBM?: List Price, $49.00
    Chip Wars: List Price, $29.95

    First Option Goes SaaS with iSeries Watchdog Power Systems i: Thinking Inside the Box

    Leave a Reply Cancel reply

Volume 9, Number 37 -- December 2, 2009
THIS ISSUE SPONSORED BY:

SEQUEL Software
WorksRight Software
Profound Logic Software

Table of Contents

  • Retrieving and Storing SQL Source for DB2 Database Objects
  • Ken Likes FMTDATE
  • Admin Alert: Creating a High-Priority Batch Subsystem

Content archive

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

Recent Posts

  • The Power11 Transistor Count Discrepancies Explained – Sort Of
  • Is Your IBM i HA/DR Actually Tested – Or Just Installed?
  • Big Blue Delivers IBM i Customer Requests In ACS Update
  • New DbToo SDK Hooks RPG And Db2 For i To External Services
  • IBM i PTF Guide, Volume 27, Number 33
  • Tool Aims To Streamline Git Integration For Old School IBM i Devs
  • IBM To Add Full System Replication And FlashCopy To PowerHA
  • Guru: Decoding Base64 ASCII
  • The Price Tweaking Continues For Power Systems
  • IBM i PTF Guide, Volume 27, Numbers 31 And 32

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