Day-Of-The-Week App (DOTWAPP)

Algorithm Description

Rev. 2/10/2012, 1/24/2014

 

Let MM/DD/YYYY denote the date of interest. YYYY must be in the domain of 1900 through 2099.

Let YY denote the last 2 digits of the year (i.e., YYYY % 100).

 

Year code

The year code equals the integer result of YY/12, plus the remainder of that division, plus the integer result when the remainder is divided by 4. Finally, subtract 1 if the year is 20YY.

 

Month code

The month code can be obtained from a lookup table, where the codes for MM values of 01 through 12 are as follows: 0 3 3 6 1 4 6 2 5 0 3 5.

 

Day code

The day code is simple: DD. The only exception would be for dates of January 1 through February 29 in a leap year, in which case we use DD – 1 instead of DD. Rule: Subtract 1 if the date of interest is in January or February of a leap year.

 

Overall code

The overall code for the date MM/DD/YYYY is the sum of the previous 3 codes, namely year code + month code + day code, mod 7. After performing this operation, interpret 1-5 as Monday through Friday. Saturday is 6, and Sunday is 0.