Return to the RPG Tips
Ways to get the day of the week ( mon, tue.... sun)
Fill "DateTest" with any Sunday's date and use "DateIn" as your target date. Then run this bit. "indx" will be the day of the week where 0=Sunday, 6=Saturday. (Test it though - I may be off a day) C* C DateIn subdur DateTest days:*d 7 0 C days div 7 days C mvr indx 1 OR Here is another way to get the day of the week ( mon, tue.... sun). MEMBER: SRVPGM /DEFINE DSpec /COPY ROUTINES/QRPGLESRC,SRVPGMCPY /UNDEFINE DSpec ... /eject P DayOfWeek B EXPORT ***** DayOfWeek - Calculates day of week (Monday = 1, Tuesday = 2, etc * - for any date. * - Input: WorkDate (Date field in *USA format) * - Result: WorkDay (Single digit numeric) D PI 1S 0 D WorkDate D CONST D AnySunday S D INZ(D'04/02/1995') D WorkNum S 7 0 D WorkDay S 1S 0 C WorkDate SubDur AnySunday WorkNum:*D C WorkNum Div 7 WorkNum C MvR WorkDay C If WorkDay < 1 C Return WorkDay + 7 C Else C Return WorkDay C EndIf P DayOfWeek E ... MEMBER: SRVPGMCPY ... D DayOfWeek PR 1S 0 D AnyDate D CONST DATFMT(*USA) ... Sample use: Calculates the day of the week as a single digit numeric. Accepts: A type 'D' date field, any valid format Returns: A single digit numeric. 1=Monday, 7=Sunday Sample: D Sample S D D daynbr S 1S 0 C *usa move *date sample C* If sample = '02-22-1999' then daynbr = 1 C Eval daynbr=DayOfWeek(sample)
[report a broken link by clicking here]