• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • How Do I Format Date Literals? Let Me Count The Ways

    May 2, 2012 Hey, Ted

    I have a strange SQL problem. I have an SQL DELETE command that works perfectly in interactive SQL. But when I use Run SQL Statement (RUNSQLSTM) to execute it, it does not find any rows to delete.

    –Jabir

    Strange, indeed. I gave Jabir some suggestions, but none of them helped. Jabir found his problem himself. In one of those environments (he didn’t say which), the date format was *MDY, while the date format of the other one was *DMY. SQL was interpreting a date value in two different ways. It’s fortunate that Jabir did not test with a date that has the same number for month and day (such as January 1), otherwise he might have installed the error into production.

    To the database manager, a date is a serial number. The value assigned to a particular date is of no importance to us. All we need to know is that the serial number of today is one more than the serial number of yesterday’s date and one less than that of tomorrow’s date.

    However, dates are something different to humans. Dates are a combination of year, month, and day. The database allows humans to enter dates as strings, and different interfaces show the same data in different human-readable formats. But how a date is displayed has nothing to do with how the database manager stores it.

    According to the SQL reference manual, you may specify a date literal in any of these format:

    • The job’s default date format
    • The ANSI/ISO SQL standard date format (DATE ‘yyyy-mm-dd’)
    • Any of the IBM SQL standard date formats (ISO/JIS, EUR, USA)
    • Unformatted Julian format (‘yyyyddd’)

    For example, assume that the default date format of a job is *MDY. You may use any of the following SELECT statements to retrieve January 3, 2010, sales orders.

    Job date format:

    SELECT * FROM SALESORDH WHERE ORDERDATE = '01/03/10'
    

    ANSI/ISO SQL standard:

    SELECT * FROM SALESORDH WHERE ORDERDATE = DATE '2010-01-03'
    

    IBM standard ISO and JIS formats:

    SELECT * FROM SALESORDH WHERE ORDERDATE = '2010-01-03'
    

    IBM standard USA format:

    SELECT * FROM SALESORDH WHERE ORDERDATE = '01/03/2010'
    

    IBM standard EUR format:

    SELECT * FROM SALESORDH WHERE ORDERDATE = '03.01.2010'
    

    Unformatted Julian format:

    SELECT * FROM SALESORDH WHERE ORDERDATE = '2010003'
    

    As I see it, you can never go wrong with good ol’ IBM standard ISO format.

    –Ted



                         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
    OCEAN User Group

    OCEAN TechCon26

    It’s a New Era for IBM i !

    July 23 – Online
    July 24 – In Person at Vanguard University in Costa Mesa, CA

    Attend TechCon26 for in-person networking, essential skills to use right now, live demos, and technical insights!

    Through June 25th, the registration fee for July 24th is $95 for OCEAN members and includes the online day, July 23rd.

    OCEAN Membership: A one-year Individual OCEAN Membership is $95 and a Corporate Membership is $325. A Corporate Membership would allow your entire company to attend OCEAN events at member rates.

    LEARN MORE

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Tembo Application Generation:  Reclaim your heritage with ADSERO OPTIMA!
    Tributary Systems:  Storage Director, a disk-to-disk-to-tape solution. Download the case study.
    COMMON:  Join us at the 2012 Conference & Expo, May 6 - 9 in Anaheim, CA

    IT Jungle Store Top Book Picks

    BACK IN STOCK: Easy Steps to Internet Programming for System i: List Price, $49.95

    The iSeries Express Web Implementer's Guide: List Price, $49.95
    The iSeries Pocket Database Guide: List Price, $59
    The iSeries Pocket SQL Guide: List Price, $59
    The iSeries Pocket WebFacing Primer: List Price, $39
    Migrating to WebSphere Express for iSeries: List Price, $49
    Getting Started with WebSphere Express for iSeries: List Price, $49
    The All-Everything Operating System: List Price, $35
    The Best Joomla! Tutorial Ever!: List Price, $19.95

    CL Error-Handling With APIs Admin Alert: Secrets Of The IBM i IPL Parameters

    Leave a Reply Cancel reply

Volume 12, Number 12 -- May 2, 2012
THIS ISSUE SPONSORED BY:

Infor
WorksRight Software
American Top Tools

Table of Contents

  • CL Error-Handling With APIs
  • How Do I Format Date Literals? Let Me Count The Ways
  • Admin Alert: Secrets Of The IBM i IPL Parameters

Content archive

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

Recent Posts

  • GenAI Is The Death Of Deterministic Project Budgeting
  • PTC Adds Support For VS Code With Implementer 12.7
  • Guru: Single Threading A Program Execution
  • As I See It: Push Back
  • IBM i PTF Guide, Volume 28, Number 21
  • Progress And Frustration With IBM i Security, Fortra Finds
  • In The Trenches With: JAMS Software
  • Guru: Where’s The Table?
  • Lightedge To Start Selling IBM PowerVS to IBM i Customers
  • IBM i PTF Guide, Volume 28, Number 20

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