! PROGRAM : DATE - This calculates the day of the week from a given
! month, day, and year
! AUTHOR : Bob Livesay; Data Pulse, Inc.
! We got this code out of a book of handy subroutines.
! I don't like its use of simplistic data names but it
! seems to work so I decided not to mess with it.
! NOTE: It is up to you to verify the validity of the
! date and the year must really be 4 digits.
!------------------------------------------------------------------------
START'JOB:
MO=2 : DA=27 : YR=1987
gosub GET'DAY
?tab(-1,0); "When the date is "; MONTH(MO); " "; &
DA using "#Z"; ", "; YR using "####"; " "; &
"The day is "; DAY(DAY'OF'WEEK)
end
GET'DAY:
I1=int((YR-1500)/100)
A=I1*5+(I1+3)/4
I2=int(A-int(A/7)*7)
Y2=int(YR/100)
Y3=int(YR-Y2*100)
A=Y3/4+Y3+DA+MONTH'CODE(MO)+I2
DAY'OF'WEEK=int(A-int(A/7)*7)+1
if MO>2 goto WRAPUP'DATE
if Y3=0 then A=I1-1 :&
T1=int(A-int(A/4)*4) :&
if T1=0 then DAY'OF'WEEK=DAY'OF'WEEK-1 :&
goto WRAPUP'DATE
T1=int(YR-int(YR/4)*4)
if T1<>0 goto WRAPUP'DATE
if DAY'OF'WEEK=0 then DAY'OF'WEEK=6
DAY'OF'WEEK=DAY'OF'WEEK-1
WRAPUP'DATE:
if DAY'OF'WEEK=0 then DAY'OF'WEEK=7
return