An algorithm to know the day of the week for a given date (method valid for dates from 1800s to 2000s)
How can you quickly and accurately calculate the day of the week associated with a specific date? Use the following calculations:
Start by taking the last two digits of the year, this is your
startingNumber
.
Divide the
startingNumber
by four and ignore the remainder.
Add the result to
startingNumber
.
Find the month code:
In leap years, subtract one from the month code for January and February.
Find if the year is leap. (Century years must divisible by 400, non-century year, last two digits must divisible
by 4)
Add the month code number.
Add the day of the month.
If year is in 2000s subtract 1, if year is in 1800s add 2.
Find the remainder of dividing the total by 7.
Find the day of the week according to the day codes. Starting Saturday: 0, Sunday: 1, ... , Friday: 6