Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Day-of-Week Routine

602 views
Skip to first unread message

Susan St. John-Parsons

unread,
Apr 18, 1997, 3:00:00 AM4/18/97
to

Can anyone either pass along or refer me to a REXX routine that will
return the day of the week, e.g. "Sunday", when a date in ccyymmdd
format is provided as argument.

Thanks.

*************************************************************************
Susan St.John-Parsons, Project Leader * Phone: (212) 854-3298
Administrative Information Services * Fax: (212) 854-4043
COLUMBIA UNIVERSITY * ********
2960 Broadway, Mail Code 7505 * INTERNET: as...@cuvmc.cc.columbia.edu
New York, New York 10027 * ss...@columbia.edu
* ********
*************************************************************************

Michael Tanzer

unread,
Apr 19, 1997, 3:00:00 AM4/19/97
to

Susan St. John-Parsons (AS...@CUVMC.AIS.COLUMBIA.EDU) wrote:

: Can anyone either pass along or refer me to a REXX routine that will


: return the day of the week, e.g. "Sunday", when a date in ccyymmdd
: format is provided as argument.

/* WEEKDAY */
/* Author = Michael Tanzer, Melbourne */
arg date
if words(date)=0 | date='?' | date='HELP' then do
say 'Format: WEEKDAY yyyymmdd'
exit
end

parse var date year +4 month +2 day +2
m = month
if m<3 then do
m = m+12
year = year-1
end
y = year%100
c = year - (year%100)*100
d = day

w = ( d + ((m+1)*26)%10 + c + (c%4) + (y%4) - (2*y) )//7
if w<0 then w = 7+w

d.0 = 'Saturday'
d.1 = 'Sunday'
d.2 = 'Monday'
d.3 = 'Tuesday'
d.4 = 'Wednesday'
d.5 = 'Thursday'
d.6 = 'Friday'
say d.w

--
+---------------------------+------------------------------------------+
| mta...@netspace.net.au | This box intentionally left blank. |
| Michael Tanzer | |
+---------------------------+------------------------------------------+

Vasilis Vlachoudis

unread,
Apr 19, 1997, 3:00:00 AM4/19/97
to

On Fri, 18 Apr 1997, Susan St. John-Parsons wrote:

> Can anyone either pass along or refer me to a REXX routine that will
> return the day of the week, e.g. "Sunday", when a date in ccyymmdd
> format is provided as argument.
>

> Thanks.

/* ------------------ DayOfWeek -------------------- */
/* return day of week 0=Sun, 1=Mon, ... 6=Sat */
DayOfWeek: procedure
if arg() = 3 then parse arg day,month,year
else parse arg day '/' month '/' year
if month < 3 then do
month = month + 10
year = year - 1
end; else month = month - 2
century = year % 100
Yr = year // 100
Dw = (((26*Month - 2) % 10) + Day + Yr + (Yr % 4) +,
(Century % 4) - (2 * Century)) // 7;
if Dw < 0 then DayOfWeek = Dw + 7
else DayOfWeek = Dw
return DayOfWeek

Karlhanns Spiegel

unread,
Apr 19, 1997, 3:00:00 AM4/19/97
to

Ich fand zum Thema Day-of-Week Routine, 18.04.97
von AS...@CUVMC.AIS.COLUMBIA.EDU

> Can anyone either pass along or refer me to a REXX routine that will
> return the day of the week, e.g. "Sunday", when a date in ccyymmdd
> format is provided as argument.

please send it me too,
also I need a way for current week from "DATE"
thanks.

--
.- so long, Karlhanns.

*Greetings from Marbach/N. - FRG -- birthplace of Fr.Schiller*


Bernie Schneider

unread,
Apr 20, 1997, 3:00:00 AM4/20/97
to

On Fri, 18 Apr 1997 17:44:59 EST, "Susan St. John-Parsons"
<AS...@CUVMC.AIS.COLUMBIA.EDU> wrote:

>Can anyone either pass along or refer me to a REXX routine that will
>return the day of the week, e.g. "Sunday", when a date in ccyymmdd
>format is provided as argument.
>

> Thanks.
>
>*************************************************************************
>Susan St.John-Parsons, Project Leader * Phone: (212) 854-3298
>Administrative Information Services * Fax: (212) 854-4043
>COLUMBIA UNIVERSITY * ********
>2960 Broadway, Mail Code 7505 * INTERNET: as...@cuvmc.cc.columbia.edu
>New York, New York 10027 * ss...@columbia.edu
> * ********
>*************************************************************************

Susan,

I think the following will do it for you. It returns a day number
(0-6), in the variable DOW, which you can convert to the day name. I
hurriedly converted this from an old BASIC program I had laying
around. Since I don't understand the math, I can't comment the
algorithm, but I believe it's based on Zeller's congruence.

==================================================

mm = 1
dd = 1
yyyy = 1970
call dow
say dow
mm = 1
dd = 12
yyyy = 1996
call dow
say dow
mm = 6
dd = 26
yyyy = 1941
call dow
say dow
exit
dow:
n = trunc((13*(mm+10-trunc((mm+10)/13)*12)-1)/5)+dd+77
n = n
+trunc(5*(yyyy+trunc((mm-14)/12)-trunc((yyyy+trunc((mm-14)/12))/100)*100)/4)
n = n +
trunc((yyyy+trunc((mm-14)/12))/400)-trunc((yyyy+trunc((mm-14)/12))/100)*2
dow = n - 7*trunc(n/7)
return

==================================================================

-- Bernie --
Bernie Schneider: bern...@prodigy.net
========================================================================
The individual has always had to struggle to keep from being overwhelmed
by the tribe. To be your own man is a hard business. If you try it, you
will be lonely often, and sometimes frightened. But no price is too high
to pay for the priviledge of owning yourself. << Rudyard Kipling >>

Michel Castelein

unread,
Apr 21, 1997, 3:00:00 AM4/21/97
to

k...@mirror.ludwigsburg.netsurf.de (Karlhanns Spiegel) wrote:


>> Can anyone either pass along or refer me to a REXX routine that will
>> return the day of the week, e.g. "Sunday", when a date in ccyymmdd
>> format is provided as argument.

>please send it me too,


>also I need a way for current week from "DATE"
>thanks.

The following 4-digit year algoritms have been tested (by Harold
Zbiegien,
bb...@Cleveland.Freenet.Edu) for dates in the range 15 October 1582 -
31 December 9999.
I implemented them in REXX coding.


/* REXX exec CONVERT1
Converts "YYYYMMDD" into (1) Julian date "YYYYNNN" (NNN is 001-366)
and (2) day-of-week.
(1): Algorithm 398 in the Oct 1970 Communication of the ACM,
by Richard A. Stone.
(2): added by Harold Zbiegien.
*/
arg YYYY +4 MM +2 DD
if YYYY // 4 = 0 then LY = 1 ; else LY = 0
if YYYY // 100 = 0 then LY = 0
if YYYY // 400 = 0 then LY = 1 /* LY is 1 if it is a leap year
*/
NNN = TRUNC(((MM + 2) * 3055) / 100) + DD - 91
if NNN > (59 + LY) then NNN = NNN - 2 + LY
NNN = RIGHT(NNN,3,0)
T = TRUNC(YYYY / 100) - 6 - TRUNC(YYYY / 400)
DOW = (NNN + TRUNC((YYYY * 5) / 4) - LY - T) // 7
/* DOW is 0-6, 0=Sunday, 1=Monday, etc.)
*/
array = 'Sunday Monday Tuesday Wednesday Thursday Friday Saturday'
day_of_week = WORD(array,DOW+1)
say YYYY || MM || DD '=' YYYY || NNN || ',' day_of_week


/* REXX exec CONVERT2
Converts Julian date "YYYYNNN" into (1) "YYYYMMDD"
and (2) day-of-week.
This is a reversal of routine CONVERT1, worked out by Harold
Zbiegien

*/
arg YYYY +4 NNN
if YYYY // 4 = 0 then LY = 1 ; else LY = 0
if YYYY // 100 = 0 then LY = 0
if YYYY // 400 = 0 then LY = 1 /* LY is 1 if it is a leap year
*/
WORK = NNN
if WORK > (59 + LY) then WORK = WORK + 2 - LY
MM = TRUNC(((WORK + 91) * 100) / 3055)
DD = (WORK + 91) - TRUNC((MM * 3055) / 100)
DD = RIGHT(DD,2,0)
MM = MM - 2
MM = RIGHT(MM,2,0)
T = TRUNC(YYYY / 100) - 6 - TRUNC(YYYY / 400)
DOW = (NNN + TRUNC((YYYY * 5) / 4) - LY - T) // 7
/* DOW is 0-6, 0=Sunday, 1=Monday, etc.)
*/
array = 'Sunday Monday Tuesday Wednesday Thursday Friday Saturday'
day_of_week = WORD(array,DOW+1)
say YYYY || NNN '=' YYYY || MM || DD || ',' day_of_week


/* REXX exec CONVERT3
Converts Julian date "YYYYNNN" into Lilian integer date (9 digits).
Cf "Computer processing of dates outside the twentieth century"
by B. G. Ohms, IBM Systems Journal, volume 25 no 2, 1986.
*/
arg YYYY +4 NNN
LIL = TRUNC(((YYYY - 1201) * 36525) / 100) - 139444 + NNN ,
- TRUNC((YYYY - 1201) / 100) ,
+ TRUNC((YYYY - 1201) / 400)
LIL = RIGHT(LIL,9,0)
say YYYY || NNN '= Lilian date' LIL


/* REXX exec CONVERT4
Converts Lilian integer date into Julian date "YYYYNNN".
Cf "Computer processing of dates outside the twentieth century"
by B. G. Ohms, IBM Systems Journal, volume 25 no 2, 1986.
*/
arg LIL
CLD = TRUNC(((LIL + 139444) * 100) / 3652425)
NNN = CLD + LIL + 139444 - TRUNC(CLD / 4)
WORK = TRUNC((NNN * 100) / 36525)
IF (NNN * 100) // 36525 = 0 then WORK = WORK - 1
NNN = NNN - TRUNC((WORK * 36525) / 100)
NNN = RIGHT(NNN,3,0)
YYYY = WORK + 1201
say 'Lilian date' RIGHT(LIL,9,0) '=' YYYY || NNN


/* REXX exec CONVERT5
Converts Lilian integer date into day-of-week.
By Harold Zbiegien (E-mail bb...@Cleveland.Freenet.Edu).
*/
arg LIL
DOW = (LIL + 4) // 7 /* DOW is 0-6, 0=Sunday, 1=Monday, etc.)
*/
array = 'Sunday Monday Tuesday Wednesday Thursday Friday Saturday'
day_of_week = WORD(array,DOW+1)
say 'Lilian date' RIGHT(LIL,9,0) '=' day_of_week


/* REXX exec CONVERT6
Converts "YYYYMMDD" into Julian date "YYYYNNN".
Cf "The Year 2000 Computing Crisis" by J.T. and M.J. Murray.
*/
arg YYYY +4 MM +2 DD
if YYYY // 4 = 0 then LY = 1 ; else LY = 0
if YYYY // 100 = 0 then LY = 0
if YYYY // 400 = 0 then LY = 1 /* LY is 1 if it is a leap year
*/
NNN = TRUNC(3 / (MM + 1)) * (31 * (MM - 1) + DD) ,
+ TRUNC((MM + 9) / 12) * (TRUNC(((305 * (MM - 1) - 15) ,
+ TRUNC((MM + 3) / 12) * 5 * TRUNC(18 / MM)) / 10) + DD + LY)
NNN = RIGHT(NNN,3,0)
say 'YYYYMMDD' YYYY || MM || DD '= YYYYNNN' YYYY || NNN


/* REXX exec CONVERT7
Converts "YYYYMMDD" into day-of-week.
This is a Zeller's congruence algorithm submitted by Mike Carroll
to the bit.listserv.ibm-main group on 5 May 1995.
*/
arg YYYY +4 MM +2 DD
if MM < 3 then do ; WMM = MM + 12
WYYYY = YYYY - 1
end
else do ; WMM = MM
WYYYY = YYYY
end
DOW = (DD + 1 + (WMM * 2) + TRUNC(((WMM + 1) * 3) / 5) ,
+ WYYYY + TRUNC(WYYYY / 4) - TRUNC(WYYYY / 100) ,
+ TRUNC(WYYYY / 400)) // 7
/* DOW is 0-6, 0=Sunday, 1=Monday, etc.)
*/
array = 'Sunday Monday Tuesday Wednesday Thursday Friday Saturday'
say 'YYYYMMDD' YYYY || MM || DD '=' WORD(array,DOW+1)


Regards,

Michel

Michel Castelein,
OS/390 (MVS) System Engineer & Education Consultant
---------------------------------------------------
E-mail: Mic...@Jeeves.be
Home page: http://www.club.innet.be/~pub00543/
company: JEEVES CONSULTING N.V.
Mechelsesteenweg 277,
B - 1800 Vilvoorde (Belgium)
phone +32-2-2516650 / fax +32-2-2525755


ora...@ibm.net

unread,
Apr 21, 1997, 3:00:00 AM4/21/97
to

In <1997041821...@mailrelay1.cc.columbia.edu>, "Susan St. John-Parsons" <AS...@CUVMC.AIS.COLUMBIA.EDU> writes:
>Can anyone either pass along or refer me to a REXX routine that will
>return the day of the week, e.g. "Sunday", when a date in ccyymmdd
>format is provided as argument.
>
> Thanks.
>
>*************************************************************************
>Susan St.John-Parsons, Project Leader * Phone: (212) 854-3298
>Administrative Information Services * Fax: (212) 854-4043
>COLUMBIA UNIVERSITY * ********
>2960 Broadway, Mail Code 7505 * INTERNET: as...@cuvmc.cc.columbia.edu
>New York, New York 10027 * ss...@columbia.edu
> * ********
>*************************************************************************
try this:

Gruesse aus Mauerbach
Otto Raeder

/* ----------------------------------------------------------------- */
/* ** Julian Day, Montenbruck p. 50 */
parse arg y m d .

g1 = 15821004 /* greg-jul calendar correction */
g2 = 15821015

gw = y*10000 + m*100 + d;
if (gw>g1)&(gw<g2) then return 0
if m>2 then do; yy=y; mm=m; end
else do; yy=y-1; mm=m+12; end
if gw<=g1 then b=-2
else b=yy%400-yy%100
jul=(365.25*yy)%1+(30.6001*(mm+1))%1+b+1720996+d+.5;
return jul
/* ------------------------------------------------------------------ */
/* sample use: */

d=trunc(jul2dat(1997 4 21)//7

/* d=0 to 6 starting with sunday */
/* ------------------------------------------------------------------ */

William H. Geiger III

unread,
Apr 21, 1997, 3:00:00 AM4/21/97
to


In <1997041821...@mailrelay1.cc.columbia.edu>, on 04/18/97
at 05:44 PM, "Susan St. John-Parsons" <AS...@CUVMC.AIS.COLUMBIA.EDU>
said:

>Can anyone either pass along or refer me to a REXX routine that will
>return the day of the week, e.g. "Sunday", when a date in ccyymmdd format
>is provided as argument.

Here it is hope this helps:

/* dow.cmd
* Calc Day of Week
* by William H. Geiger III
* Geiger Consulting
* whg...@amaranth.com
* 21 April 1997
*/

days="31 59 90 120 151 181 212 243 273 304 334 365"
dow="Monday Tuesday Wednesday Thursday Friday Saturday Sunday"

parse arg date

/* parse date into year,month, & day */

year=left(date,4)
month=substr(date,5,2)
day=right(date,2)

/* calc number of leap days since 1 Jan 0001 */

lp4=trunc(year/4-(3*(year/100+1))/4)

/* calc number of days in the current year */

if month<>1 then dy=word(days,(month-1))+day
else dy=day

/* calc # of days since 01 January 0001 */

bd=(year-1)*365+lp4+dy

/* calc day of the week */

weekday=word(dow,(bd//7)+1)
say date "=" weekday


--
-----------------------------------------------------------
William H. Geiger III http://www.amaranth.com/~whgiii
Geiger Consulting Cooking With Warp 4.0

Author of E-Secure - PGP Front End for MR/2 Ice
PGP & MR/2 the only way for secure e-mail.

Finger whg...@amaranth.com for PGP Key and other info
-----------------------------------------------------------


Esther Schindler

unread,
Apr 21, 1997, 3:00:00 AM4/21/97
to

"Susan St. John-Parsons" <AS...@CUVMC.AIS.COLUMBIA.EDU> writes:

:>Can anyone either pass along or refer me to a REXX routine that will


:>return the day of the week, e.g. "Sunday", when a date in ccyymmdd
:>format is provided as argument.

There's one in _Teach Yourself REXX in 21 Days_; you could search around for
anything with "Zeller's Congruence" elsewhere, if you don't like that one.

I'll paste in the code we wrote for Teach Yourself REXX (though I hope you're
so grateful that you feel compelled to run out and buy several copies of the
book!).

--Esther Schindler
co-author, Teach Yourself REXX in 21 Days, SAMS, 1994


/* Zeller's Congruence */

SAY "Enter the month and year:"
PULL month year

day = 1
dow = Zeller() + 1

/* space over days before first of month */
week = ''
DO dow - 1
week = week || ' '
END

/* get number of days for month (ignores leap years) */
SELECT
WHEN month = 2 THEN
mthLen = 28
WHEN month = 4 | month = 6 | month = 9 | month = 11 THEN
mthLen = 30
OTHERWISE
mthLen = 31
END

/* display the heading */
SAY
SAY Center(month || '/' || year, 21)
SAY ' S M T W T F S'

/* build each week and display it */
DO wk = 1 TO 6 UNTIL day > mthLen
DO dow = dow TO 7 UNTIL day > mthLen
week = week Format(day, 2)
day = day + 1
END
dow = 1
SAY week
week = ''
END

EXIT

/* Zeller's Congruence */
Zeller:
IF month > 2 THEN
DO
adjMonth = month - 2
adjYear = year
END
ELSE
DO
adjMonth = month + 10
adjYear = year - 1
END

century = adjYear % 100
yearInCentury = adjYear - 100 * century
dayOfWeek = ((13 * adjMonth - 1) % 5 + day + yearInCentury + ,
yearInCentury % 4 + century % 4 - century - century + 77) ,
// 7


Martin Brown

unread,
Apr 21, 1997, 3:00:00 AM4/21/97
to

Susan St. John-Parsons wrote:
>
> Can anyone either pass along or refer me to a REXX routine that will
> return the day of the week, e.g. "Sunday", when a date in ccyymmdd
> format is provided as argument.

OK, my turn. Doesn't not include adjustment for centuries, but
that's pretty easy. This works for the 20th.

/* Calculate day of week
*/

arg mm dd
yy

monthtoday ='1 4 4 0 2 5 0 3 6 1 3
6'
days = 'SAT SUN MON TUE WED THU
FRI'

term1 = yy % 12 /* Gain a day every 12 years
*/
term2 = yy // 12 /* And a day every year after that
*/
term3 = (yy // 12) % 4 /* And an extra every 4th year
*/
term4 = word(monthtoday,mm) /* And some each month
*/
leapadj = ((yy // 4) = 0) & mm <= 2 /* Unleap Jan & Feb
*/

daynum = (term1 + term2 + term3 + term4 + dd - leapadj) //
7

Say
word(days,daynum+1)

Christian Robert

unread,
Apr 22, 1997, 3:00:00 AM4/22/97
to

Susan St. John-Parsons wrote:
>
> Can anyone either pass along or refer me to a REXX routine that will
> return the day of the week, e.g. "Sunday", when a date in ccyymmdd
> format is provided as argument.
>
> Thanks.

>
> > Susan St.John-Parsons, Project Leader * Phone: (212) 854-3298
> Administrative Information Services * Fax: (212) 854-4043
> COLUMBIA UNIVERSITY * ********
> 2960 Broadway, Mail Code 7505 * INTERNET: as...@cuvmc.cc.columbia.edu
> New York, New York 10027 * ss...@columbia.edu
> * ********
>

[C:\] cat test.cmd
/* Object rexx enhanced date */

Sorted = '19970422'
Say Date('w',Sorted,'s')

Exit

[C:\] test
Tuesday

[C:\]

Xtian.

Mark Schlegel

unread,
Apr 24, 1997, 3:00:00 AM4/24/97
to

Esther Schindler (est...@primenet.com) wrote:
: "Susan St. John-Parsons" <AS...@CUVMC.AIS.COLUMBIA.EDU> writes:
:
: :>Can anyone either pass along or refer me to a REXX routine that will

: :>return the day of the week, e.g. "Sunday", when a date in ccyymmdd
: :>format is provided as argument.
:
: There's one in _Teach Yourself REXX in 21 Days_; you could search around for

: anything with "Zeller's Congruence" elsewhere, if you don't like that one.

another thing that would really useful, I want to get the output from
the PPP.EXE driver, but the problem is that you can't just use the
usual rxqueue way of getting the output because ppp.exe is a persistent
program, not like firing off a "dir" or "pstat" to the cmd session, for
example:

....in rexx cmd file ...

"dir | rxqueue /fifo"
do until queued() = 0
parse pull aline
say aline
end

this works fine for something that terminates quickly like a dir
but with ppp.exe it NEVER returns until you do a cntrl+c or
cntrl+break (or run pppkill from a cmd line). So how can I
get a line at a time from the stdout/stderr even if the
thing never terminates? I have a cludge now that just looks
in the rxqueue every 3 seconds then it returns to the parent .cmd
file when it sees a key bit of text that IBM put in the PPP.EXE that
it always says when the connection is complete

(eg: [PPP] Enter Ctrl-C or Ctrl-Break to End Session)

in parent .cmd file:

call ppprun.cmd output.
say 'connect results'
do i = 1 to output.0
say output.i
end

and in ppprun.cmd:
/* ppprun.cmd */

FLAG = "false"
options = "com1 57600 defaultroute connect ""slattach -f my.rsp"""
"@detach ppp.exe" options | rxqueue /fifo"

cnt = 0
call syssleep '15' /* wait for at least something to get to queue */
do forever
call syssleep '3'
do until queued() = 0 /*
parse pull aline
cnt = cnt + 1
outp.cnt = aline
first = wordpos("Enter", aline)
second = wordpos("Ctrl-C", aline)

/* if line read contains final line
[PPP] Enter Ctrl-C or Ctrl-Break to End Session */
if (first \= 0 & second \= 0 & first = second - 1) then
do
outp.0 = cnt
leave /* leave forever loop */
end
end
end
return outp. /* return stem to parent */


what's a better way?

Mark

Dion Gillard

unread,
Apr 24, 1997, 3:00:00 AM4/24/97
to

In message <5jmelp$ha3$1...@news.crocker.com> - schl...@crocker.com (Mark

Schlegel)24 Apr 1997 01:57:13 GMT writes:
|
| what's a better way?
Use Linenin('QUEUE:') it waits for input....


dIon, Multitask Consulting
Work: http://www.multitask.com.au
NetRexx: http://www.multitask.com.au/netrexx
RxExtras: http://www.multitask.com.au/rxextras


Mark Schlegel

unread,
Apr 25, 1997, 3:00:00 AM4/25/97
to

Dion Gillard (di...@multitask.com.au) wrote:
: In message <5jmelp$ha3$1...@news.crocker.com> - schl...@crocker.com (Mark

: Schlegel)24 Apr 1997 01:57:13 GMT writes:
: |
: | what's a better way?
: Use Linenin('QUEUE:') it waits for input....
:

But that still won't let me get each line immediately ...
I suppose the only way that could be done would be to
get each line via your linein("QUEUE:") suggestion then
send them back one at a time via a named pipe to the
parent .cmd file. I don't want to get them all in one bundle at once.

Mark

Dion Gillard

unread,
Apr 27, 1997, 3:00:00 AM4/27/97
to

In message <5jqj9u$rgo$1...@news.crocker.com> - schl...@crocker.com (Mark

Schlegel)25 Apr 1997 15:40:46 GMT writes:
|
| : Use Linenin('QUEUE:') it waits for input....
| :
|
| But that still won't let me get each line immediately ...
| I suppose the only way that could be done would be to
| get each line via your linein("QUEUE:") suggestion then
| send them back one at a time via a named pipe to the
| parent .cmd file. I don't want to get them all in one bundle at once.
Huh....what do you mean by immediately? As soon as something is placed on the
QUEUE, Linein will return with the data from the queue, And it wont check the
keyboard - it waits for something from the queue....I must be missing
something...
0 new messages