RPGIII Get Day of Week Routine (Zeller Conguence)
Published by: **Bob Cozzi** on 22 Dec 2011 view comments(2)

This is the RPGIII source code to calculate the day of the week, using Zeller's Congruence formula:

***************************************************************** ** Zeller's Congruence in RPGIII by Bob Cozzi, July 2006 ** (c) 2006 by Bob Cozzi. All rights reserved. *********************************************************** ** Temp/work fields for calculation ITEMPS IDS I B 1 40DAYOWK I B 5 80TEMP1 I B 9 120TEMP2 ** ** Put the date into this Data Structure IZDATE IDS I 1 40NYEAR I 5 60NMONTH I 7 80NDAY ** Demo date is 23-July-1958 (should be a Wednesday) C Z-ADD1958 NYEAR C Z-ADD07 NMONTH C Z-ADD23 NDAY C EXSR ZDAY C MOVE *ON *INLR *********************************************************** ** This subroutine calculates the day of the week using ** Zeller's congruence. ** --Converted to RPGIII by Bob Cozzi, July 2006 ** (c) 2006 by Bob Cozzi. All rights reserved. ** Permission to use for any purpose is hereby granted ** provided credit to the copyright holder is included. ** ** Input fields: ** zDate Date in YYYYMMDD format ** nDay Day of month ** nYear Year ** nMonth Month *********************************************************** CSR ZDAY BEGSR ** If the month Jan or Feb, then adjust it to fit the algorythm. ** Also subtract 1 from the year in this situation. C NMONTH IFLT 3 C ADD 12 NMONTH C SUB 1 NYEAR C ENDIF ** ** Perform Zeller's formula to calculate the day of the week. C NMONTH MULT 13 TEMP1 C ADD 3 TEMP1 C DIV 5 TEMP1 C ADD NDAY TEMP1 C ADD NYEAR TEMP1 C NYEAR DIV 4 TEMP2 C ADD TEMP2 TEMP1 ** C NYEAR DIV 100 TEMP2 C SUB TEMP2 TEMP1 C NYEAR DIV 400 TEMP2 C ADD TEMP2 TEMP1 C DIV 7 TEMP1 C MVR DAYOWK ** ** At this point, we have the day of the week from Zeller. ** However, it is zero-based (Mon=0, Tues=1, Wed=3... etc.) ** This procedure is designed to return ones-based values ** as follows: (Sun=1, Mon=2, Tues=3... etc.) ** ** We need to convert the result from Zeller, as follows: ** If day is greater than 5, subtract 5 from the day. ** Otherwise, increase the day by 2. ** For example: Sun=6 so 6 - 5 = 1 ** Mon=0 so 0 + 2 = 2 ** Tue=1 so 1 + 2 = 3 ** Wed=2 so 2 + 2 = 4 ** Thu=3 so 3 + 2 = 5 ** Fri=4 so 4 + 2 = 6 ** Sat=5 so 5 + 2 = 7 ** ** If you prefer 0=Monday based return value, simply delete ** the code upto but NOT including the RETURN opcode. C DAYOWK IFGT 5 C SUB 5 DAYOWK C ELSE C ADD 2 DAYOWK C ENDIF CSR ENDZDY ENDSR

(Sign in to Post a Comment)

Comment on: RPGIII Get Day of Week Routine (Zeller Conguence)

Posted: 12 years 5 months 1 days 11 hours 3 minutes ago

Posted: 12 years 5 months 1 days 11 hours 3 minutes ago

Wow, 2006 and still using RPGIII! Though I'm guessing from the last comment line that there was some thought given to making it an RPGIV procedure

Comment on: RPGIII Get Day of Week Routine (Zeller Conguence)

Posted: 12 years 5 months 1 days 10 hours ago

Edited: Thu, 22 Dec, 2011 at 15:49:56 (4536 days ago)

Posted: 12 years 5 months 1 days 10 hours ago

Edited: Thu, 22 Dec, 2011 at 15:49:56 (4536 days ago)

Haha, yes the shop I was consulting in needed RPGIII day of the week.

Originally we called an RPG IV program and did the CEExxxx thing. But then I found Zeller's formula and wanted to convert it to RPG. Since we don't really need it in RPG IV (at the time) I thought why not write it in RPGIII for the poor old bastards using III. Hence the subroutine.

Turns out to be one of my more widely-used routines (sadly). I'm archiving it here for future googler's or whatever displaces google, to find it.