What's the day today (or other dates)? Task

Write a program or a function that calculates a week-day name of a date which a user inputs.

Input &amp; Output

Input is a string, YYYYMMDD.

Example of input values:


20110617 : June 17, 2011
19040229 : February 29, 1904
06661225 : December 25, 666
00000101 : January 1, 0
99991231 : December 31, 9999


You may assume that all inputs are valid. Note that year zero is valid.

Output is an integer between 0 and 6. Each integer represents a week-day name. You can decide freely which integer represents a week-day name, like this one


0 : Monday
1 : Tuesday
2 : Wednesday
...
6 : Sunday


(in order) or this one


0 : Monday
1 : Wednesday
2 : Sunday
...
6 : Saturday


(not in order).

Test Cases


Input     Week-day   Output ([0..6 -> Monday..Sunday] is used in this example.)

20110617  Friday     4
19500101  Sunday     6
22220202  Saturday   5
19000228  Wednesday  2
19000301  Thursday   3
19450815  Wednesday  2
19040229  Monday     0
19040301  Tuesday    1
17760704  Thursday   3
20000228  Monday     0
20000229  Tuesday    1
20000301  Wednesday  2
20121223  Sunday     6
00000401  Saturday   5
66660606  Wednesday  2
59161021  Saturday   5


Restriction

You must not use any kind of function/class/... which are related to timestamp or date, like Date class in Java/JavaScript/ActionScript, or getdate function in PHP.

You should use Gregorian calender, which is used by many people now.

Of course, shortest code wins. If two code have same length, then the code with highest votes wins.

(Due: When there's more than 5 codes which has more than (or equal) +1 votes.)
PHP - 101 97 103 125 characters

Sakamoto Algorithm
0 = Sunday

Code
&lt;?php fscanf(STDIN,&quot;%4d%2d%2d&quot;,$y,$m,$d);@$a=a032503514624;$y-=$m&lt;3;$z=$y+1;echo($y+$y/4%$z-$y/100%$z+$y/400%$z+$a[$m]+$d)%7;

Note
Unfortunately, due to PHP's dynamic, weak typing, the Sakamoto algorithm doesn't function properly without explicitly flooring each division operation.