Algorithm wanted

James Hayes 33500911 at sdcc3.UUCP
Wed Dec 5 13:39:08 AEST 1984


>    Does someone "out there" know of an algorithm (or can direct me
>to a source) which will calculate the Day of the Week (e.g. Monday,
>Tuesday, etc) based on the month, the day and the year?
>It will be greatly appreciated....
>            - Rob DeMillo
>              Madison Academic Computing Center

Sorry Folks, it's in BASIC...

X=INT(.6+1/M) : Y1=Y-X : M1=M+12*X : X=Y1/100
N4=INT(X/4) : N3=INT(X) : N2=INT((5*Y1)/4) : N1=INT(13*(M1+1)/5)
X=N1+N2-N3+N4+D-1
FD=X-(7*INT(X/7))

On entry:  Y=year (must be after 1752)
	   D=day
	   M=month

On exit:   FD will contain an integer from 0 to 6. 0=Sunday and
						   6=Saturday.
                       (And as you might have guessed 1-5 fall
			in-between.)

			James Hayes
			{ucbvax,sdcsvax}!sdcc3!33500911


[SPEED ISN'T EVERYTHING. YOU HAVE TO BE CORRECT SOME OF THE TIME]



More information about the Comp.sources.unix mailing list