On Wed, Dec 3, 2014 at 7:17 AM, John E <whattssonn@xxxxxxxxx> wrote:
From http://nl.wikipedia.org/wiki/Weeknummer (which is in dutch) :
To calculate the ISO weekday (1=monday) for a given date:
I don't read Dutch, but even so, I didn't see any weekday calculations
on that page. I saw a bunch of tables and algorithms relating to ISO
week *number* (which makes sense, given the title of the article).
Calculating the *weekday* in pure RPG (IV) doesn't have to be as
complicated as what you've provided, though. Now, before I go any
further, let me just state for the record that I recommend using the
available SQL functions, including converting the source to SQLRPGLE
if it isn't already.
For those who *for whatever reason* want to get the ISO weekday in RPG
IV without SQL, you can make use of the fact that the date type
supports proleptic Gregorian dates back to 0001-01-01. Also make use
of the fact that 0001-01-01 was (proleptically speaking) a Monday.
Assuming you keep all the declarations as before, simply do
d = %diff(date:d'0001-01-01':*d);
return %rem(d:7) + 1;
Note that the result of %DIFF gives you the number of days AFTER
0001-01-01 (so 0001-01-02 is Day 1). Also note that calculating the
day of the week (whether ISO or any other reasonable scheme) should
NEVER be more complicated than one %DIFF, one %REM, and optionally
*one* fudge at the end to adjust the offset.
The ISO week number calculations are necessarily more complicated.
I'm not sure they have to be as complicated as what you've provided,
but I don't have the time to search for a simpler implementation or
come up with my own right now.
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives