Newsletters   Subscriptions  Forums  Store  Media Kit  About Us  Contact  Search   Home 
fhg
Volume 4, Number 10 -- March 31, 2004

Determine Elapsed Days, Weekdays, and Workdays


Hey, Ted:

Finding the number of days between two dates is a common requirement in IT shops. We have a method that works well for us. It lets us include or exclude holidays and weekends.

We have a calendar file that has a record for every date between January 1, 1940, and December 31, 2039. It has quite a few fields, but the three that pertain to this discussion are DATE, DAYOFWEEK, and HOLIDAY. DATE is the date itself, defined with the date data type. DAYOFWEEK is a one-digit packed decimal number in the range 1 (Sunday) to 7 (Saturday), the same values SQL returns through the DAYOFWEEK function. Holiday is also a one-digit packed decimal number that contains a zero (not a holiday) or 1 (holiday).

Here's the SQL command to find the number of days between two dates.

select count(*)          
  from calendar          
 where date > '12/29/03' 
   and date <= '01/12/04'

Here's how we find the number of elapsed weekdays.

select count(*)                  
  from calendar                  
 where dayofweek between 2 and 6 
   and date > '12/29/03'         
   and date <= '01/12/04'        

We can find the number of workdays by omitting holidays and weekends.

select count(*)                 
  from calendar                 
 where dayofweek between 2 and 6
   and holiday = 0              
   and date > '12/29/03'        
   and date <= '01/12/04'       

--Paul


Good idea, Paul. A calendar file is as handy as a pocket.

Finding the number of days between two dates is easy to do. Here's another method that doesn't require a calendar file.

select days('01/12/04') - days('12/29/03') 
  from sysibm/sysdummy1                    

The DAYS function returns an ordinal value representing the number of days since January 1 of the year 1. The difference between two ordinal values is the date difference. But if you want to omit weekends or holidays, this method won't work.

--Ted

Sponsored By
CLIENT SERVER DEVELOPMENT

Never Worry About Time Again

Daylight savings time coming up? Need to synchronize your iSeries or AS/400 with a network time device? Is your AS/400 time in sync with other servers on your network? Participating in HIPAA or EDI transactions?

Let Atomic Time Manager 400 synchronize your clocks!

Atomic Time Manager 400 is an easy-to-use utility developed by Client Server Development. It resides on your iSeries and automatically adjusts your hardware and software clocks, keeping them in sync with other servers on your network.

The Atomic Time Manager 400 also automatically adjusts your clocks to "spring forward" and "fall back" when daylight savings time changes. Forget about complex offsets, SNTP configuration, and scheduling CL programs to adjust time--the Atomic Time Manager 400 does it for you.

The best part, at only $499 per iSeries or AS/400, the Atomic Time Manager 400 is the affordable solution for your time management needs.

Click here to learn more about the Atomic Time Manager 400
and order yours through Guild Companies now!


Editors: Howard Arner, Joe Hertvik, Ted Holt,
Shannon O'Donnell, Kevin Vandever
Managing Editor: Shannon Pastore
Contributing Editors: Raymond Everhart, G. Wayne Hawks,
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:

Guild Companies
Client Server Development
GST
SuSE Linux
COMMON


BACK ISSUES

TABLE OF
CONTENTS
Step by Step: RPG IV and Interactive Web Pages

Determine Elapsed Days, Weekdays, and Workdays

Thinking in Sets

Admin Alert: Moving ASCII Data Between IFS and Windows

OS/400 Alert: Virus Programming for the Novice



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