× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



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.

John Y.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.