Return to the RPG Tips
Calculate day of the week
H DATFMT(*ISO) D INDATE DS D DATE D DATFMT(*USA) INZ D DATE_MM 2S 0 OVERLAY(DATE:1) D DATE_DD 2S 0 OVERLAY(DATE:4) D DATE_YYYY 4S 0 OVERLAY(DATE:7) D DS D DEC31 D DATFMT(*ISO) INZ(D'0001-12-31') D DEC31_YYYY 4S 0 OVERLAY(DEC31:1) D Sunday C D'1999-12-19' D Days S 15P 0 * Packed numeric parameters C *ENTRY PLIST C DATE_MM PARM G$MM 2 0 C DATE_DD PARM G$DD 2 0 C DATE_YYYY PARM G$YYYY 4 0 C PARM G$DW 1 0 * Calculate the day of the year (julian days) * (Number of days between the input date and the previous Dec 31) C EVAL DEC31_YYYY = DATE_YYYY - 1 C DATE SUBDUR DEC31 G$JD:*DAYS * Calculate the day of the week (0 = Sunday) C DATE SUBDUR Sunday Days:*DAYS C DIV 7 DAYS C MVR G$DW 1 0 C IF G$DW < 0 C EVAL G$DW = G$DW + 7 C ENDIF C* G$JD DSPLY G$DW C RETURN Barbara Morris
[report a broken link by clicking here]