Return to the RPG Tips
How do I convert a date from, say, 1/5/2000 to "Wednesday, January 05, 2000?"
The code below takes a date (DateIn) and builds a text string (DateString) from it. This code uses a pointer (PtrDays) to aim the numbered day of the week at its proper location in the AryDays array. Similarly, the PtrMonths pointer assigns the proper month after picking out the date's individual components with the new EXTRCT (Extract date) operation. The date string is then built through a simple concatenation expression. ********************************************************************** * * DateString Builds a date string for DateIn * * Example: Saturday, October 14, 1995 * ********************************************************************** D AryDays S 9 DIM(7) D CTDATA PERRCD(7) D AryMonths S 9 DIM(12) D CTDATA PERRCD(6) D DateIn S D D DateString S 30 D DayOfWeek S 7 0 D PtrDays S * INZ(%ADDR(AryDays)) D PtrMonths S * INZ(%ADDR(AryMonths)) D StrDayOfWk S 9 BASED(PtrDays) D StrMonth S 9 BASED(PtrMonths) D WorkDay S 2 D WorkMonth S 2 0 D WorkYear S 14 * Determine day of week (1 7) C DateIn SUBDUR D'1899 12 30' DayOfWeek:*D C DIV 7 DayOfWeek C MVR DayOfWeek C IF DayOfWeek < 1 C EVAL DayOfWeek = DayOfWeek + 7 C ENDIF * Extract date components C EXTRCT DateIn:*Y WorkYear C EXTRCT DateIn:*M WorkMonth C EXTRCT DateIn:*D WorkDay * Set pointers within arrays C EVAL PtrDays = %ADDR(AryDays(DayOfWeek)) C EVAL PtrMonths = %ADDR(AryMonths(WorkMonth)) * Build string C EVAL DateString = %TRIM(StrDayOfWk) + ', ' + C %TRIM(StrMonth) + ' ' + C WorkDay + ', ' + C WorkYear **CTDATA AryDays Sunday Monday Tuesday WednesdayThursday Friday Saturday **CTDATA AryMonths January February March April May June July August SeptemberOctober November December
[report a broken link by clicking here]