working days calculations
Paul Hoeflinger
phoeflin@fmo.com
Thu, 4 May 2000 14:30:04 -0400
To solve the problem of calculating the number of working days between two
calendar dates I created a data set within an Image data base. All of the
elements in this data set are keys. The primary key (PC-CAL-DATE) is the
calendar date in PHDate format. Another element is (PC-WORK-DAY). This is a
sequentially assigned number to each valid working date. The third element is
(PC-WORK-DATE) which is a valid working date in PHDate format. I have a program
that reads a data file of holidays, i.e. non working days, and creates the image
of this data set once for each calendar date. If the calendar date corresponds
to a holiday or a Saturday or Sunday the element PC-WORK-DATE is assigned the
next valid working day. I have my data set loaded with three years of calendar
dates with the current year 2000 in the middle. This way I can calculate the
elapsed work days anytime within a three year time span. The way I do this is
access the data set via PC-CAL-DATE for my first date and then access this same
data set with the alias option via my second date. I can then subtract the
values in PC-WORK-DAY to find the working days between the two dates. An example
would be:
The first date Wed, April 19. The data set shows a work day of 572. The
second date is Mon, April 24. The data set shows a work day of 574. When you
subtract these numbers you get an answer of 2. There are two working days
between the two dates (Thur, April 20 & Mon, April 24).
The PH Dictionary definition follows with an example of my data via query.
Record: PRCH-CALNDR
of File: DBCRIB
Organization: DETAIL
Type: TURBOIMAGE
Open: PRCH-CALNDR of DBCRIB
Record Size: 10 Bytes
-- Record Contents --
Item Type Size Occ Offset
PC-CAL-DATE INTEGER SIGNED 4 0
PC-WORK-DAY INTEGER SIGNED 2 4
PC-WORK-DATE INTEGER SIGNED 4 6
-- Index Contents --
** PC-CAL-DATE is a 4 byte REPEATING ALTERNATE index **
** that links to PRCH-CAL-DATE **
Segment Type Size Ord Offset
PC-CAL-DATE INTEGER SIGNED 4 A 0
** PC-WORK-DAY is a 2 byte REPEATING PRIMARY index **
** that links to PRCH-DAY **
Segment Type Size Ord Offset
PC-WORK-DAY INTEGER SIGNED 2 A 0
===============================================================================
PC-CAL-DATE =20000419 This is Wed, April 19. It is a valid working
day so the element PC-WORK-DATE is the same.
PC-WORK-DAY =572
PC-WORK-DATE =20000419
PC-CAL-DATE =20000420 This is Thur, April 20. It is a valid working
day so the element PC-WORK-DATE is the same. Notice
PC-WORK-DAY =573 that PC-WORK-DAY has incremented by 1.
PC-WORK-DATE =20000420
PC-CAL-DATE =20000421 This is Fri, April 21. Our plant did not work
that day. Notice that PC-WORK-DATE is the next working
PC-WORK-DAY =574 date for our plant. It has skipped Fri, Sat &
Sun and is set to Mon, April 24.
PC-WORK-DATE =20000424
PC-CAL-DATE =20000422 This is Sat, April 22. Notice that the
element PC-WORK-DAY did not increase. This is the work day that
PC-WORK-DAY =574 is assigned to Mon, April 24.
PC-WORK-DATE =20000424
PC-CAL-DATE =20000423 This is Sun, April 23.
PC-WORK-DAY =574
PC-WORK-DATE =20000424
PC-CAL-DATE =20000424 This is Mon, April 24. The next working date.
PC-WORK-DAY =574
PC-WORK-DATE =20000424
PC-CAL-DATE =20000425 This is Tue, April 25.
PC-WORK-DAY =575
PC-WORK-DATE =20000425
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Subscribe: "subscribe powerh-l" in message body to majordomo@lists.swau.edu
Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
This list is closed, thus to post to the list, you must be a subscriber.