I just used the algorithm to compute the day of the week of my date of birth, which I know was a Sunday; however the algorithm turned up Tuesday instead. Maybe the algorithm needs tweaking.
I am trying to follow this algorithm, but I'm going wrong somewhere and can't seem to figure it out:
So take today's date as an example, 8th May 2012 (Tuesday) or 8/5/2012Day of Week -- A program for converting Gregorian dates in the form month-day-year to day of the
week is the following. Let the Gregorian date be represented by M/D/Y where we have the following
definitions:
M is the month of the year. Let m be the month number derived from M by the rule m is M-2
if M>=3 and m is M + 10 otherwise.
d is the day of the month.
y is the year of the century.
c is the number of the previous century.
The algorithm is as follows:
(a) A is the integer part of (13m - 1)/5.
(b) B is the integer part of y/4.
(c) C is the integer part of c/4.
(d) D = A + B + C + d + y - 2c.
(e) Make R equal to the remainder of D/7.
(f) Interpret R as Sunday if R = 0, Monday if R is 1, etc.
The month is greater than 3, so m = (5 - 2) = 3
d = 8
y = 2012
c = 20
A = ((13 * 3) - 1) / 5 = 7.6, however above it says the integer part, so A = 7
B = 2012 / 4 = 503
C = 20 / 4 = 5
D = 7 + 503 + 5 + 8 + 2012 - (2 * 20)
D = 2495
R = 2495 % 7 = 3
So we would interpret today's date as a Wednesday? I must be doing something wrong here, can anyone spot what it is?
Thank You
-Sam
I just used the algorithm to compute the day of the week of my date of birth, which I know was a Sunday; however the algorithm turned up Tuesday instead. Maybe the algorithm needs tweaking.