• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Date Field Odds and Ends

    June 9, 2010 Hey, Competent Professional

    Thirty years ago we stored dates and times in alphanumeric and numeric fields, because we didn’t have date, time, and timestamp data types. Many shops still store dates in alpha and numeric fields, some of them because they still run applications that date back to those dates, others because they’ve never bothered to learn to use the new data types. Here are three tips for working with date fields. I hope you enjoy them. Feel free to add to the discussion.


    Hey, Ted:

    In the old days, when dates were stored in numeric or alpha fields, we used invalid date values to indicate special conditions. A ship date of all 5s, for example, might mean that an order was on hold and could not be shipped. A ship date of zeros might mean that an order had not yet been shipped. But database fields that are defined with the date/time/timestamp data types cannot contain invalid values. How do you handle special values in such fields?

    –Bob

    I’ve seen this done two ways. The way I don’t like is to use a valid value that you would never use otherwise. For example, most factories in the United States are closed on December 25, so you could use that date to indicate that an order is on hold. I do not like that method because it requires counterintuitive logic in programs and queries.

    select;
        when ShipDate = d'9999-12-31';
           // process not shipped 
        when %subdt(ShipDate:*months) = 12
         and %subdt(ShipDate:*days)   = 25;
           // process on-hold
        other;
           // process shipped order
    endsl;
    

    The other method of which I am aware is to use status fields in conjunction with date fields. That is, you would have a shipping date field and a shipping status field. The shipping status field might have values of blank (not shipped), H (on hold), and S (shipped). The logic is no more complicated than with the first method, and I think it can be easier to read and understand. The downside is that you have to update two fields, not one, when modifying a date.

    D NotShipped      c                   const(' ')
    D OnHold          c                   const('H')
    D Shipped         c                   const('S')
    
     /free
         *inlr = *on;
         select;
             when ShipStatus = NotShipped;
                // process not shipped
             when ShipStatus = OnHold;
                // process on-hold
             other;
                // process shipped order
         endsl;
    


    Hey, Ted:

    Just because a date is a valid one does not mean it is reasonable. We had an example of this recently. Someone transposed two digits of a date when keying. Had someone else not caught the error, the customer’s order would have been delayed several years!

    –Ron

    I know this seems like common sense and we shouldn’t have to say it, but I have seen a lot of software that accepts any valid date, even dates far back in the past or far into the future. (I’ve also seen software that allows any date, even invalid ones.) Thanks for the reminder.


    Hey, Ted:

    Please explain DATFMT. I have never used it and seem to be getting by quite well without it.

    –Ben

    A date is a date is a date–almost. Dates of formats with two-digit years are limited to the range 1940 to 2039. But the system will let you compare an ISO date to a MDY date, for instance, or a EUR date to a Julian date.

    DATFMT is used in DDS for physical and logical files to indicate the format of the date. Practically speaking, the only benefit I’ve ever seen to using this keyword is for the people who use Query. If your people are accustomed to viewing dates in six-digit month-day-year format, for example, you can specify DATFMT(*MDY), along with DATSEP(‘/’), and people using Query will see the dates in that format. This is consistent with the philosophy of database management systems, which says that users should be able to view data in the format of their choice, regardless of how the data is stored in the database.

    In physical files, DATFMT is only allowed for the date data type, but in logical fields you can also use DATFMT for character, zoned decimal, and packed decimal data that redefines date fields in the physical file.

    In RPG programs, you can use DATFMT in H and D specs. In H specs, DATFMT specifies the internal format for date literals, and default internal format for date fields. The default format is *ISO. You may override the format for date variables by using DATFMT in the D specs.

    As long as you’re willing to work with dates in ISO format, you have no need of DATFMT. The important thing is that you’re using the date/time/timestamp data types, not numeric and character fields and variables.



                         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
    DRV Tech

    Get More Out of Your IBM i

    With soaring costs, operational data is more critical than ever. IBM shops need faster, easier ways to distribute IBM applications-based data to users more efficiently, no matter where they are.

    The Problem:

    For Users, IBM Data Can Be Difficult to Get To

    IBM Applications generate reports as spooled files, originally designed to be printed. Often those reports are packed together with so much data it makes them difficult to read. Add to that hardcopy is a pain to distribute. User-friendly formats like Excel and PDF are better, offering sorting, searching, and easy portability but getting IBM reports into these formats can be tricky without the right tools.

    The Solution:

    IBM i Reports can easily be converted to easy to read and share formats like Excel and PDF and Delivered by Email

    Converting IBM i, iSeries, and AS400 reports into Excel and PDF is now a lot easier with SpoolFlex software by DRV Tech.  If you or your users are still doing this manually, think how much time is wasted dragging and reformatting to make a report readable. How much time would be saved if they were automatically formatted correctly and delivered to one or multiple recipients.

    SpoolFlex converts spooled files to Excel and PDF, automatically emailing them, and saving copies to network shared folders. SpoolFlex converts complex reports to Excel, removing unwanted headers, splitting large reports out for individual recipients, and delivering to users whether they are at the office or working from home.

    Watch our 2-minute video and see DRV’s powerful SpoolFlex software can solve your file conversion challenges.

    Watch Video

    DRV Tech

    www.drvtech.com

    866.378.3366

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Help/Systems:  Use Robot/SPACE for your IBM i disk storage management
    ManageEngine:  Who says iSeries systems monitoring software has to be expensive?
    COMMON:  Join us at the Fall 2010 Conference & Expo, Oct. 4 - 6, in San Antonio, Texas

    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

    Kronos Touts iSeries Central Customer Two Top i Concerns and a Bunch of Little Ones

    Leave a Reply Cancel reply

Volume 10, Number 18 -- June 9, 2010
THIS ISSUE SPONSORED BY:

SEQUEL Software
WorksRight Software
Botz & Associates, Inc.

Table of Contents

  • Re-Adopt Authority Utility
  • Date Field Odds and Ends
  • Admin Alert: How To Run NetServer from the Green Screen in 10 Minutes

Content archive

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

Recent Posts

  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20
  • POWERUp 2025 –Your Source For IBM i 7.6 Information
  • Maxava Consulting Services Does More Than HA/DR Project Management – A Lot More
  • Guru: Creating An SQL Stored Procedure That Returns A Result Set
  • As I See It: At Any Cost
  • IBM i PTF Guide, Volume 27, Number 19

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