fhg
Volume 9, Number 37 -- December 2, 2009

Ken Likes FMTDATE

Published: December 2, 2009

Hey, Ted:

I immediately loaded and tested your FMTDATE function when I saw it in Four Hundred Guru. I just wanted to say "Thank You!" The tool is fantastic! We have mostly ISO and LONGJUL dates in our files and it is always a pain when converting or throwing math at them. No more!

Here is an example of some date math I tried on a LONGJUL order date and an ISO invoice date to calculate "Days-To-Ship" using your function:

SELECT fmtdate(OrderDate, 'LONGJUL', 'ISO-') Ordered,
       fmtdate(InvDate, 'ISO', 'ISO-') Invoiced,
       Date(fmtdate(InvDate, 'ISO', 'ISO-'))-
       Date(fmtdate(OrderDate, 'LONGJUL', 'ISO-'))
  FROM ORDERS

--Ken


I got a good bit of positive response to my Format Date (FMTDATE) function. I've enjoyed using the function in my work, and evidently other readers have, too.

Ken's use of FMTDATE to simplify date arithmetic is good, but it's got a tiny error in it that I want to correct. Subtracting one date from another yields a date duration, which can be misleading. Here's Ken's query over some test data I created.

ORDERED     INVOICED    Numeric Expression
2008-12-31  2009-01-15              15    
2009-01-01  2009-03-31             230    

There are not 230 days between January 1 and March 31. The value 230 means two months and 30 days. I have discussed date durations before.

To make this work, use the DAYS function to create each date to a number that represents the number of days since January 1 of the year 1 A.D.

SELECT fmtdate(OrderDate, 'LONGJUL', 'ISO-') Ordered,   
       fmtdate(InvDate, 'ISO', 'ISO-') Invoiced,        
       days(Date(fmtdate(InvDate, 'ISO', 'ISO-')))-     
       days(Date(fmtdate(OrderDate, 'LONGJUL', 'ISO-')))
  FROM Orders

Here are the results of using the DAYS function.

ORDERED     INVOICED    Numeric Expression
2008-12-31  2009-01-15                15  
2009-01-01  2009-03-31                89  

This makes more sense to me, anyway. I've never thought that it was a good idea to show date durations to end users.

--Ted


Ken had one more question. . .

Hey, Ted:

When invoking FMTDATE from RPG, I am getting an error due to the number of parameters being invalid. I see that it's because the service program expects five parameters to be passed. Correct me if I'm wrong, but I can only assume that SQL is more forgiving when invoking a function with un-sent trailing parameters, because I'm only passing three on the function call.

With this in mind, I tweaked your code (sorry) to specify options(*nopass) for the last two parameters and recreated module, service program, and function. This took care of my RPG invocation of the service program, but I notice that now an SQL visit to the function returns no nulls as it nicely did before. I could have two versions of FMTDATE--one to create the service program for RPG without the last two parms, and one WITH the parms. I could use the latter to create the function and keep the NULL return capability for SQL, and the former for use in RPG programs without having to add the last two parameters. Do you agree?

--Ken


It is possible to invoke FMTDATE from RPG. After all, it's a service program. Here's how it's done.

H option(*srcstmt: *nodebugio)

D FmtDate         pr            10a   varying
D   inDate                       8p 0 const
D   inFromFmt                    8a   varying const
D   inToFmt                      8a   varying const
D   inNullArray                  6a   const
D   ouNull                       5i 0

D ShipDate        s              7p 0
D ShipDateP       s             10a
D ShipDateNull    s              5i 0

 /free
     *inlr = *on;
     ShipDateP = FmtDate(ShipDate: 'cymd': 'mdyy/': *blanks: ShipDateNull);
     return;

But there's no need to go to all that trouble, Ken. I recommend you use the built-in functions that come with RPG instead of FMTDATE.

monitor;
   ShipDateP = %char(%date(ShipDate:*cymd):*usa);
on-error;
   ShipDateNull = -1;  // or whatever else you might want to do
endmon;

I'm glad that Ken and others found FMTDATE helpful.

--Ted


RELATED STORIES

Formatting Dates with SQL

Query and Date Durations



                     Post this story to del.icio.us
               Post this story to Digg
    Post this story to Slashdot


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
E-mail: software@worksright.com
Web site: www.worksright.com


Senior Technical Editor: Ted Holt
Technical Editor: Joe Hertvik
Contributing Technical Editors: Erwin Earley, Brian Kelly, Michael Sansoterra
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

Sponsored Links

Profound Logic Software:  FREE OnDemand Webinar. Learn how to easily build and extend i apps
LANSA:  Take your apps to a new dimension with RAMP. FREE Webinar!
Manta Technologies:  Your complete source for IBM i training


 

IT Jungle Store Top Book Picks

Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
The iSeries Express Web Implementer's Guide: List Price, $49.95
The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
The System i Pocket RPG & RPG IV Guide: List Price, $69.95
The iSeries Pocket Database Guide: List Price, $59.00
The iSeries Pocket SQL Guide: List Price, $59.00
The iSeries Pocket Query Guide: List Price, $49.00
The iSeries Pocket WebFacing Primer: List Price, $39.00
Migrating to WebSphere Express for iSeries: List Price, $49.00
Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
Getting Started with WebSphere Express for iSeries: List Price, $49.00
Can the AS/400 Survive IBM?: List Price, $49.00
Chip Wars: List Price, $29.95


 
The Four Hundred
IBM Slashes Power Systems Memory Prices

A New Look for the COMMON Session Grid

SSD Performance: Be Careful Before You Buy

Mad Dog 21/21: The Fox in IBM's Storage Henhouse

How Does 800,000 CPWs in a 2U Server Grab You?

Four Hundred Stuff
Simply Continuous Aims to Narrow 'Recovery Gap' with DR Solution

ManageEngine Adds i OS Support to Application Performance Tool

User Activity Monitoring from PacketMotion to Support i OS

Single-Platform, Technology-Focused Security Unwise Says Ex-IBMer Botz

NGS Adds PDF and Excel Report Generation to BI Suite

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

System i PTF Guide
November 28, 2009: Volume 11, Number 48

November 21, 2009: Volume 11, Number 47

November 14, 2009: Volume 11, Number 46

November 7, 2009: Volume 11, Number 45

October 31, 2009: Volume 11, Number 44

October 24, 2009: Volume 11, Number 43

October 17, 2009: Volume 11, Number 42

TPM at The Register
Sun VirtualBox gets live migration

Server sales stabilizing, says study

Fujitsu gung-ho on eight-core 'Venus' Sparc

IBM shows off Power7 HPC monster

Super Micro primes 'Magny-Cours' Opterons

Big Blue murders Cell blade servers

How to network at a supercomputing show

HP takes one in the servers

Cray previews XT6 Opteron nodes

PC sales bounce up (and down)

IBM chases HP (and Sun) with tiny mem prices

Nvidia previews next-gen Fermi GPUs

THIS ISSUE SPONSORED BY:

SEQUEL Software
WorksRight Software
Profound Logic Software


Printer Friendly Version


TABLE OF CONTENTS
Retrieving and Storing SQL Source for DB2 Database Objects

Ken Likes FMTDATE

Admin Alert: Creating a High-Priority Batch Subsystem

Four Hundred Guru

BACK ISSUES




 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2009 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement