Newsletters   Subscriptions  Forums  Store  Media Kit  About Us  Contact  Search   Home 
fhg
Volume 4, Number 14 -- April 28, 2004

Find Database Records with Invalid Dates

Hey, Ted:


We store dates in YYYYMMDD format in packed decimal fields in our database. This served us well when we wrote all our applications in green-screen RPG. Now that we're using other technologies, invalid dates (like all zeros, all nines, or April 31) cause us problems. Is there a way in SQL to test the validity of a date? Something similar to RPG's TEST op code with the D extender would be great.

--Kenny


I don't know of an SQL function that will tell you whether a numeric field contains a valid date, so I wrote one.

Use the method of your choice (interactive SQL, iSeries Navigator, Howard Arner's SQLThing) to run the following SQL code on your iSeries machine.

create function IsValidDate (parmDate decimal(8))
 returns integer                                 
 language sql                                    
 deterministic                                   
 contains sql                                    
 not fenced                                      
 called on null input                            
 no external action                              
 set option datfmt = *iso                             
 begin                                                
    declare chDate8 char (8);                          
    declare chDate10 char (10);                        
    declare dDate date;                                
    declare bValid integer;                            
    declare continue handler for sqlexception          
       set bValid = -1;                                
    set bValid = 0;                                    
    set chDate8 = digits(parmDate);                    
    set chDate10 = substr(chdate8,1,4) || '-' ||       
                   substr(chdate8,5,2) || '-' ||       
                   substr(chdate8,7,2);                
    set dDate = chDate10;                              
    return bValid;                                     
 end                                                  
 

This function returns zero if the date is valid and negative one if the date is invalid.

The following example uses the IsValidDate function to find records with an invalid JEDATE.

SELECT *
  FROM gljnl
  WHERE IsValidDate(jedate) < 0                                

--Ted

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


Editors: Howard Arner, Joe Hertvik, Ted Holt,
Shannon O'Donnell, Kevin Vandever
Managing Editor: Shannon Pastore
Contributing Editors: Joel Cochran, Wayne O. Evans, Raymond Everhart,
Bruce Guetzkow, Marc Logemann, David Morris
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.

THIS ISSUE
SPONSORED BY:

Advanced Systems Concepts
COMMON
Guild Companies
WorksRight Sofware
Profound Logic Software


BACK ISSUES

TABLE OF
CONTENTS
Cross-Reference Your Procedures

Using RPG As Your ASP Language, Part 1

Keep Your Users Informed

Find Database Records with Invalid Dates

OS/400 Alert: Googlize Your Enterprise



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