Basic Math/Dates

Advertisement


Question
QUESTION: Josh, this might be a bit out of the norm for you, but according to your profile, I suspect you might be able to help.

Math and magic are two of my favorite subjects, and my question touches on both. I was totally intrigued when I found this page on the net:
http://mathforum.org/dr.math/faq/faq.calendar.html

The section down below called "How do I find the day of the week for any date?" was irresistible to me! I actually spent a few weeks practicing it, and had fun showing it off at a conference I just attended. By creating and memorizing some shortcuts, I am now able to calculate the correct day of the week in less than a minute!

However.......the formula fails when the date falls in January or February of a year ending in --00. It's frustrating as I can't seem to find a way to make the formula fit those dates.

Do you think you might be able to help me? If it would help save some time, I'm happy to share the shortcuts I invented to cut down on calculation time.

Thanks for your help, Josh! Hope you'll have as much fun with this one as I have.  :-)

Best regards,
Jan


ANSWER: Hi Jan,

This algorithm is not particularly easy to analyze. I tried Reverend Deller's method and wrote the algorithm again using the modulus and floor functions (explained below). I tried an example befitting your description and it works!

The crucial step for a leap year is to replace the year Y with Y-1 if the month happens to fall in January or February. The reason being, they are "always counted as the 11th and 12th months of the previous year." See the following example.

====================================================
Definitions:

1. The floor function, <n> returns the largest integer amongst all integers smaller than the real number n. e.g., <3.1415> = 3.

2. The modulus function, mod(N,k) is the remainder of N/k.
* A useful property is that mod(N,k)=mod(M,k) for any M=N+i*k.
e.g., For N=-5, k=4, we can select a positive M like M=-5+2*4=3. Using this property, mod(-5,4)=mod(3,4)=3

Consider the date 14 February 2000.
Let "D"=14, "M"=2, "Y"=2000.
Enumerate each day of the week, such that
{Sunday=0, Monday=1, Tuesday=2,..., Friday=5, Saturday=6}

The Deller method may be summarized as follows:

Compute f = k + <(13m-1)/5> + d + <d/4> + <c/4> - 2c,

where
[1] k=D,
[2] m=mod(M-3,12)+1,
[3] if(Y is a leap year) Y'=Y-1, else Y'=Y.
[4] c=floor(Y'/100),
[5] d=Y'-100C,

Day of week has index mod(f,7)
Note: This only works for the Gregorian system
=====================================================

Number crunching:
k=14,
m=mod(2-3,12)+1
=mod(-1,12)+1
=mod(11,12)+1
=12
Y'=2000-1=1999,
c=19,
d=99,
f=14+31+99+24+4-38=134

mod(f,7)=1 => Monday


Best regards,
Josh

---------- FOLLOW-UP ----------

QUESTION: Hi, Josh,

Yes, I'm well aware that January and February have special rules -- that's the reason I couldn't get it to work.

Using my own system, I did indeed calculate correctly for February dates in 2000 and 1800. But they don't calculate correctly in 1900 for some strange reason.

Take February 24, 1900, for example:

The month of February calculates to 31.
The day is 24.
We change the year of 1900 to 1899.
The century 18 calculates to -32.
The year is 99+24 or 123.
31+24-32+123=146

Mod of 146/7 is 6 which translates to Saturday. According to Excel, that date should be a Friday.

Oh, my gosh, I just went in to confirm with www.TimeAndDate.com, and I see that February 24, 1900 is indeed a Saturday! That means that Excel is showing the date as one weekday off.

And as I use the autofill button to fill February 24, 1900, I also see that Excel thinks that was a leap year. TimeAndDate says it was not, and so does the page with our date formula!

Interesting conundrum. Guess this means that I was calculating correctly all along....

It's not every day that I am smarter than Microsoft Excel!  ;-)


Answer
Hi, Jan,

Many people have reservation about the trustworthiness of Microsoft product. Version incompatibility, non-compliance etc. are amongst some of the better known problems. There were bugs reported some years ago which has to do with overflow in numerical calculation.

It's good to have a healthy sense of skepticism. Beware you don't take it as a source of authority. If you read the license agreement for MS product, you may find that correctness of the implementation is not guaranteed.

Basic Math

All Answers


Answers by Expert:


Ask Experts

Volunteer


Josh

Expertise

When I work through problems, I like to emphasize concepts which I believe are worth noting. I will try to answer questions in the following areas, but not at the advanced level. Algebra. Sequences & Series. Trigonometry. Functions & Graphs. Coordinate Geometry. Quadratic Polynomials. Exponential & Logarithms. Basic Calculus. Probability, Permutation and Combination. Mathematical Induction. Complex numbers. Physics problems.

Experience

I have worked as a teaching assistant in college. My hope is that more people will share knowledge without boundary, give help without seeking recognition or monetary rewards.

Education/Credentials
Bachelor degree in Engineering Science

©2012 About.com, a part of The New York Times Company. All rights reserved.