• 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
    ProData

    Simple.  Reliable.  Powerful.

    IBM i software to help you navigate your universe!

    Use these tools to get where you are going:

    DBU to easily, yet securely, access the data on your IBM i or remote system.

    RDB Connect for powerful record level access to remote data using RPG, CL or COBOL.

    SQL/Pro and Audit for reliable SQL data processing, tracking and reporting.

    And more!

    Join our DBUniverse of loyal, happy customers and experience your destination…

    Do IT with DBU!

    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

  • Big Blue Unveils Spring 2021 IBM i Technology Refreshes
  • Thoroughly Modern: Innovative And Realistic Approaches To IBM i Modernization
  • Guru: Web Services, DATA-INTO and DATA-GEN, Part 2
  • Back To The Future With A New IBM i Logo
  • IBM i PTF Guide, Volume 23, Number 14
  • When Cloud Meets DevOps on IBM i
  • JD Edwards Roadmap Reveals Decisions To Be Made
  • IBM Completes Migration of Knowledge Center to IBM Documentation
  • Four Hundred Monitor, April 7
  • Crazy Idea Number 615: Variable Priced Power Systems Partitions

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 © 2021 IT Jungle

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.