• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Formatting Dates With SQL, Take 3

    July 12, 2016 Ted Holt

    This story contains code, which you can download here.

     

    I love it when someone improves something I’ve produced. In this case, that someone was Barry Arnold, an A-1COBOL programmer with whom I had the privilege to work once upon a time. Barry improved my FMTDATE SQL function for use in his shop. Maybe his enhancement will help you, too.

    Barry’s shop, like many others, must deal with data from many different sources, and that data is often formatted in ways that are not conducive to RPG and COBOL programming. Barry found himself having to de-edit character dates before passing them to the FMTDATE function. He reasoned that FMTDATE should be able to handle the de-editing, and I have to agree.

    I modified the character version of FMTDATE in two ways:

    • I increased the size of the date (the first argument) from eight to 10 bytes to allow for edited eight-byte dates.
    • If an editing character is specified in the source format (the second argument), I remove all occurrences of the editing character from the date before attempting the conversion. In the previous version, I ignored an editing character, as I do with the numeric version of FMTDATE.

    Here’s an example:

    SELECT some_date, fmtdate(some_date,'mdy/','iso-')
      FROM mytable
    

     

    SOME_DATE

     

    FMTDATE

     

    02/28/16

     

    2016-02-28

     

    12/25/15

     

    2015-12-25

     

    12 25 15

     

    2015-12-25

     

    12-25-15

     

    null

     

     

    Notice that FMTDATE can handle internal blanks. This was not intentional; it just worked out that way. It also ignores leading and trailing blanks.

    Notice also that FMTDATE does not remove editing characters other than the one specified in the format.

    Thanks to Barry for suggesting this improvement. This would be a pitiful world if I had to think of everything myself.

    Ted Holt welcomes your comments and questions. Email him through the IT Jungle Contacts page.

     

    RELATED STORIES

    Easier Overloading of SQL Functions

    Ease the Burden of Overloading

    Formatting Dates with SQL, Take 2

     

    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

    System i Developer:  RPG & DB2 Summit - October 4-6 2016 in Chicago. Register now! COMMON:  Open Source and Systems Management at the COMMON Forum. August 24-25 in Chicago. OCEAN:  3 days of inspiration! 2016 IBM i Technical Conference, July 21-23, Costa Mesa, California

    Maxava Opens Up Bidding For iFoundation Grants A Second Look At SQL Descriptors

    Leave a Reply Cancel reply

Volume 16, Number 15 -- July 12, 2016
THIS ISSUE SPONSORED BY:

WorksRight Software
Valence Framework for IBM i
System i Developer

Table of Contents

  • A Generic Character Editing Routine
  • Formatting Dates With SQL, Take 3
  • New OLAP Aggregate Functions In DB2 for i, Part 1

Content archive

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

Recent Posts

  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

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