• 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
    Midrange Dynamics North America

    Git up to speed with MDChange!

    Git can be lightning-fast when dealing with just a few hundred items in a repository. But when dealing with tens of thousands of items, transaction wait times can take minutes.

    MDChange offers an elegant solution that enables you to work efficiently any size Git repository while making your Git experience seamless and highly responsive.

    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

    Island Pacific Completes ERP Upgrade for Clothing Retailer Apps And IBM i Evangelism

    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

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • 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

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