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

    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

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

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