Interface
| | |
DayOfWeek(J, K, I)
|
Process
BEGIN
A <- (14 - J) div 12
Y <- I - A
M <- J + 12 * A - 2
N <- (K + Y + Y div 4 - Y div 100 + Y div 400 + (31 * M) div 12) mod 7;
DayOfWeek <- N
END
Output
DayOfWeek, integer
Notes
Determines the day of the week on which a given date falls.
J is month, K is day of month and I is 4-digit year.
The algorithm is based on information at
www.smart.net/~mmontes/ushols.html#ALG [site no longer exists; jdr 1/2/2021].
DayOfWeek is a 1-digit integer corresponding to a day of the week where:
0=Sunday, 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday
Examples
Input Output
J K I DayOfWeek
7 15 1996 1
10 9 1996 3
10 31 1996 4
Notation
<- means is replaced by
J div K yields the quotient after long division of J by K
J mod K yields the remainder after long division of J by K