This is a method to find the day of the week for any date between Julius Caesar and the apocalypse, or at least until someone changes the Western calendrical system. You can also use this system, for example, to find the next Friday the 13th. I learnt it by heart years ago, and I never needed to use a calendar since that time.

You need to compute the sum of 4 numbers: one for the century, one for the year in the century, one for the month, and one for the day in the month.

All these numbers are defined modulo 7. For example, 5 is equivalent to 12 and to -2.

Step 1: the Century Number

The Century Number is not really a century number, since it considers that 1900 belongs to the 20th century, that 2000 belongs to the 21st century, and so on.
The computation mode for the Century Number is different in the Gregorian calendar and the Julian Calendar. The Gregorian calendar was introduced by Pope Gregory XIII in the year 1582, but it was adopted by other countries later. For example, the British adopted it only in September 1752, which you can check by typing cal 9 1752 under Unix.

  • In the Julian calendar, the Century Number is 0 (zero) for years that begin with 4, 11 or 18 (i.e in the 5th, 12th or 19th century). For years in other centuries, compute the difference with the next century with a Century Number equal to 0:
    Year 1752: 18 - 17 =  1
    Year 234: 4 - 2 = 2
  • In the Gregorian calendar, the Century Number is 0 for the 20th century. The following table gives the Century Number for other centuries. If you want to memorize it, or find the day of week for years in the 4th millenium, you may note that there is a pattern (hint: 1600 and 2000 are leap years, while 1700, 1800, 1900 and 2100 are not. See Gregorian calendar.)
                        The Century Number
    
       Years that begin with           Century Number
                        15..           0
                        16..           1
                        17..           3
                        18..           5
                        19..           7 = 0 mod 7
                        20..           1
                        21..           3
                        22..           5
                        23..           7 = 0 mod 7
                        24..           1
    
Step 2: the Year Number

For the Year Number, the easiest way is to start from years which Year Number is 0. Then walk to your year, and add 1 for each non-leap year you encounter, and 2 for each leap year.
The following years have a Year Number equal to 0 (hint: find the pattern if you want to learn this list by heart):

             The Year Number

                00    04    10
          21    27    32    38
          49    55    60    66
          77    83    88    94

Year 1399 has a Year Number equal to 5 = 99 - 94 + 1 (because there is one leap year, 96, in the interval)
Year 1956 has a Year Number equal to 2 = 56 - 55 + 1 (because 56 is a leap year)
Year 44 BC has a Year Number equal to 3 because 44 BC is equivalent to 57 in 1st century BC, and 57 - 55 + 1 = 3.

Step 3: The Month Number

This is the Month Number for each month:

                 The Month Number

          0   February (leap year), August
          1   February (non-leap year), March, November
          2   June
          3   September, December
          4   January (leap year), April, July
          5   January (non-leap year), October 
          6   May
Step 4: the Day Number

Congratulations, this is the end. The Day Number is simply, well, the day number in the month: 17 if this is November 17th, for instance.

Putting it all together

The sum of the previous numbers, modulo 7, gives the day of the week. 0 means Sunday, 1 means Monday, and so on.

A few examples:

   ============================================================
   Date
     Century Nb   Year Nb   Month Nb   Day Nb   Result
   ============================================================
   November 17, 2000
         1           0         1         17     19 = 5 mod 7
                                                   => Friday
   	
   September 2, 1752 (Julian calendar)
         1           4         3          2     10 = 3 mod 7
                                                   => Wednesday
   
   September 14, 1752 (Gregorian calendar)
         4           4         3          14    25 = 4 mod 7
                                                   => Thursday
   
   March 15 44BC
        -5           3         1         15     14 = 0 mod 7
                                                   => Sunday
   
   July 1st 1969
         0           4         4         21     29 = 1 mod 7
                                                   => Monday
   ============================================================

Another example: how many Friday the 13ths are there in year 2000?
Solution: Friday is 5. Subtract the day number 13, the year number 0 and the century number 1 from 5. The result is:

5 - 13 - 0 - 1 = -9 = 5 mod 7

The corresponding month is October (not January because 2000 is a leap year.)

An increasingly important survival skill in the modern world is the ability to mentally calculate on which day of the week a particular date falls. Most of us have at some time been hospitalised, caused the death of loved ones or suffered the embarrassment of public nudity due to our inability to perform this simple task. But anyway, enough about me: let us consider how best for you to avoid a similar fate.

The technique described below is due to the famous mathematician John Horton Conway, who refers to it as the Doomsday algorithm. Conway delights in asking new acquaintances their birthdates and almost instantaneously telling them on which day of the week they were born; he claims (perhaps not unreasonably) to be the fastest human date-calculator in the world.

Firstly, a little memorisation is an essential investment for the budding Doomsday algorithmist. The heart of the technique is a list of what Conway calls "Doomsdays"--one date in each month--which conveniently all fall on the same day of the week each year. (For example, in 2000 each Doomsday was a Tuesday.) The dates are as follows:

January 31st (or 32nd in a leap year--this apparent absurdity is explained below)
February 28th (or 29th in a leap year)
March 0th (see below for explanation)
April 4th
May 9th
June 6th
July 11th
August 8th
September 5th
October 10th
November 7th
December 12th
Do not give up in disgust at this point. With a couple of tricks, this list is very easy to memorise. For example, note that for all the even months except February, the month number equals the day number: 4/4, 6/6, 8/8, 10/10, 12/12. As for May, July, September and November, Conway recommends using the mnemonic "I work from 9 to 5 at the 7-11" which yields the dates 9/5, 5/9, 7/11 and 11/7. Next, remember that the last day of February is always a Doomsday--whether or not this happens to be the 28th or 29th. Since this is one day before March 1st, we list it again as "March 0th", a somewhat redundant entry but a convenient mental device when calculating dates in March. A similar illegal date is given to the January Doomsday in leap-years: "January 32nd" obviously refers to the day after January 31st, even though this is not its proper name.

Having memorised this list, you're already able to calculate any date in 2000, since we know that Doomsday 2000 is Tuesday. For example, the 4th of July in 2000 is seven days before the Doomsday (Tuesday) July 11, and is therefore also a Tuesday. January 30th 2000 comes two days before a Doomsday (2000 was a leap year so "January 32nd" is a Doomsday) and is therefore a Sunday.

The remainder of the technique involves calculating the Doomsday for any given year. The procedure is very simple and with practice will take a matter of seconds:

First, what century are we talking about? For the 2000s, as we have seen, the first Doomsday of the century is a Tuesday. In 1900, it was a Wednesday. In practice this is all you'll need to remember--everyday usage rarely requires calculation of dates outside 1900-2099. (You can easily enough find the Doomsday for other centuries yourself if necessary.)

Next comes the only bit of actual mathematics involved. Take the last two digits of the year you're working with, and do the following:

Count the number of dozens in this number (i.e., divide by 12)
Add on the remainder left over when dividing by 12
Add on the number of 4s in this remainder (i.e., divide it by 4)
For example, if we're talking about 1995, then the last two digits are 95, into which twelve divides 7 times with a remainder of 11, into which four divides 2 times. Thus the number calculated is 7+11+2=20.

This number you've just found represents the offset between that year's Doomsday and the turn-of-the-century Doomsday. In the example above, we've found that Doomsday 1995 is 20 days later than Doomsday 1900 (which was Wednesday). For our purposes multiples of seven obviously don't make any difference, so we can throw away 14 days and simply say that it's 6 days later than Wednesday, i.e., Tuesday. What this means is that in 1995, all of the dates January 31, February 28, April 4, etc., fell on Tuesdays. This makes it easy to find any other date via simple arithmetic.

There's nothing more you need to know. Practice by finding on what day of the week you were born. Here's one example to clarify: let's say you were born on October 7th, 1968. Remember that the Doomsday for 1900 was Wednesday, and we need to find by how much 1968 differs from that. Twelve divides 5 times into 68, with remainder 8. Four goes twice into this remainder. Add the three results: 5+8+2=15, which (throwing away a couple of multiples of seven, i.e., 14 days) is an offset of 1 day from 1900's Doomsday. So Doomsday 1968 is Thursday, which in particular means the 10th of October was a Thursday. Therefore the 7th of October, coming three days earlier, was a Monday.


Postscript: Here's a poetic way to describe the Doomsday algorithm, possibly due to Kate Larson (at least, it appears on her homepage at http://www.cs.wustl.edu/~ksl2/mathpoem.html):

The last of Feb., or of Jan. will do
(Except that in Leap Years it's Jan. 32)
Then for even months use the month's own day,
And for odd ones add 4, or take it away*

Now to work out your doomsday the orthodox way
Three things you should add to the century day
Dozens, remainder, and fours in the latter,
(If you alter by sevens of course it won't matter)

In Julian times, lackaday, lackaday
Zero was Sunday, centuries fell back a day
But Gregorian 4 hundreds are always Tues.
And now centuries extra take us back twos.

* According to length or simply remember,
you only subtract for September, or November.

Sure, there's the Doomsday Algorithm, but there is also a mathematical formula for determining the day of the week which is useful for working out on paper or in a computer program. Here's a simple C/C++-like function for finding the day of the week from any given date (there is a walk-through at the bottom for those of you who are not programmers). The day of the week is returned as an integer with:

Since there are numerous calendar systems, in addition to calculating based simply on the month, day, and year, there is a fourth argument allows the function to compute the day of the week for any number of systems as opposed to just the values for the Gregorian Calendar most commonly used today.

Examples:

// Begin code

int getDayOfWeek(int month, int day, int year, int CalendarSystem)
{
     // CalendarSystem = 1 for Gregorian Calendar
     if (month < 3)
     {
           month = month + 12;
           year = year - 1;
     }
     return (
             day
             + (2 * month)
             + int(6 * (month + 1) / 10)
             + year
             + int(year / 4)
             - int(year / 100)
             + int(year / 400)
             + CalendarSystem
            ) % 7;
}

// End code

For you non-programmers, here is an example:

Let's say you are trying to determine what day of the week New Years Day fell on in 1900. Since we know this happened on January 1, 1900, we just fill in the numbers based on the information above:

month          =    1
day            =    1
year           = 1900
CalendarSystem =    1 (Gregorian Calendar)
if (month < 3)
{
     month = month + 12;
     year = year - 1;
}
Since the month is 1 (which is less than 3) we add 12 to the month and subtract 1 from the year
month          =   13
day            =    1
year           = 1899
CalendarSystem =    1 (Gregorian Calendar)
return (
     day
     + (2 * month)
     + int(6 * (month + 1) / 10)
     + year
     + int(year / 4)
     - int(year / 100)
     + int(year / 400)
     + CalendarSystem
     ) % 7;

Now just substitute the values in and calculate. It should be noted that int(x) just means to convert the number to an integer by removing the decimal part of the number (do not round the number, just remove the decimal)

(1 + (2 * 13) + int(6 * (13 + 1) / 10) + 1899 + int(1899 / 4) - int(1899 / 100) + int(1899 / 400) + 1) modulus 7
Reduces to: (1 + 26 + int(8.4) + 1899 + int(474.75) - int(18.99) + int(4.7475) + 1) modulus 7
Reduces to: (27 + 8 + 1899 + 474 - 18 + 4 + 1) modulus 7
Reduces to: 2395 modulus 7

Modulus simply means to take the remainder after dividing, so 2395/7 = 342 R 1, so the day of the week is 1. From the list at the top of the writeup, you will see that this equates to Monday.

Thank you in10se, ariels, mkb.

#include<stdio.h>

main()
{
        int y;                  /* year */
        int m;                  /* month */
        int d;                  /* date (day) */
        int newdate;            /* day of the week */

        printf("Please enter the year in question:\n");
        scanf("%d", &y);
        printf("Enter the number of the month:\n");
        scanf("%d", &m);

        if (m < 3)
                {
                        m = m + 12;
                        y = y - 1;
                }

        printf("Enter the date: \n");
        scanf("%d", &d);


        newdate = (d + (2 * m) + ((6 * (m + 1)) / 10) + y + (y / 4) - 				

(y / 100) + (y / 400) + 1) % 7;

        switch (newdate)
        {
                case 0:
                {
                        puts("The day is Sunday.");
                        break;
                }
                case 1:
                {
                        puts("The day is Monday.");
                        break;
                }
                case 2:
                {
                        puts("The day is Tuesday.");
                        break;
                }
                case 3:
                {
                        puts("The day is Wednesday.");
                        break;
                }
                case 4:
                {
                        puts("The day is Thursday.");
                        break;
                }
                case 5:
                {
                        puts("The day is Friday.");
                        break;
                }
                case 6:
                {
                        puts("The day is Saturday.");
                        break;
                }
                default:
                {
                        puts("You goofed!");
                }
        }

        return 0;
}
Well, why not just keep extending the language support for this? Since this is a web-based world we live in, and as PHP is more hip than a pair of Wayfarers or anything bought at Old Navy, I thought I'd convert this to a web-based page (named, in this case, "dow.php") using PHP as the language. I'll post the code first, then explain it...


<html>
<head>
<title>Day of week</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<body>

<form name="getDate" method="post" action="dow.php">
  <table border="0" cellspacing="0" cellpadding="4">
    <tr>
      <td nowrap>
        <font size="2" face="Arial, Helvetica, sans-serif">
        Enter Date (mm/dd/yyyy): 
      </font>
      </td>
      <td nowrap>
        <font size="2" face="Arial, Helvetica, sans-serif">
        <input name="mon" type="text" size="2" maxlength="2">
        /
        <input name="day" type="text" size="2" maxlength="2">
        /
        <input name="year" type="text" size="4" maxlength="4">       
        </font>
      </td>
      <td nowrap>
        <font size="2" face="Arial, Helvetica, sans-serif">
        ex: "05/20/1960"
        </font>
      </td>
    </tr>
    <tr>
      <td>
        <font size="2" face="Arial, Helvetica, sans-serif">&nbsp;</font>
      </td>
      <td>
        <font size="2" face="Arial, Helvetica, sans-serif">
        <input name="submit" type="submit" value="Submit Date">
        </font>
      </td>
      <td>
        <font size="2" face="Arial, Helvetica, sans-serif">&nbsp;</font>
      </td>
    </tr>
  </table>
</form>
  
<?php  // begin php code

$fontStyle = "size=\"2\" face=\"Arial, Helvetica, sans-serif\"";
$dayStrings = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

if (!isset($mon) || !isset($day) || !isset($year))
  return;  // prevent processing of values not yet entered

// simple range-checking
if (($mon < 1) || ($mon > 12) || 
    ($day < 1) || ($day > 31) ||
    ($year < 0))
{ 
  echo "<b>An invalid date ($mon/$day/$year) was entered </b>";
  return;
}

if ($mon < 3)
{
  $mon = $mon + 12;
  $year = $year - 1;
}

if ($year < 1582) // account for gregorian calendar
  $greg = 1;
else
  $greg = 0;

$dow = ($day + (2 * $mon) + ((6 * ($mon + 1)) / 10) + $year + ($year / 4) -
       ($year / 100) + ($year / 400) + $greg) % 7;

echo "<font $fontStyle>";  // specify a font style

if ($dow > 6) {  // trap out-of-range errors
  echo "Something is amiss, the day ($dow) is invalid";
} else {
  echo "The day of the week for $mon/$day/$year is:
  <b>$dayStrings[$dow]</b>";
}
echo "</font>";

?>
</body>
</html>

I attempted to keep the code small, while still giving it some pizzazz so it works out-of-the-box and looks somewhat polished. The section enclosed by the PHP script identifiers ("<?php" and "?>") is a blatant rip off of the previous C code posted here, converted of course to PHP syntax. The remainder is just simple HTML code for data input, and display.

The above will display a basic HTML form where the user enters "the date" that interests them, and the page then returns which day of the week that date fell upon.

You can simply cut and paste the example into an editor, save it onto a PHP-enabled server (most are), and pull it up in your browser. If you change the saved filename to something other than "dow.php" you'll need to change the form code that links to itself by this name (I didn't use "PHP_SELF" because it's server configuration dependent).

For posterity, here's how to get the Doomsday for any century:

Memorize this: Sun-Tue-Wed-Fri. Century Doomsdays all fall on one of these days. (Mnemonic: your _son_ is going _to_ get married this Friday.)

Now remember that 1900 = Wednesday (Conway says "We-in-dis-day" -- a rather dated mnemonic as of this writeup, but maybe your birthday was in the 1900s).

The last thing to remember is that the '00' years always follow "Sun-Tue-Wed-Fri" in reverse order. So if 1900 = Wednesday, 2000 = Tuesday. You can sorta visualize this:

      S T W F
1600    *
1700  *
1800        *
1900      *
2000    *
2100  *
2200        *
2300      *
I first read this at http://rudy.ca/doomsday.html

If you are not inclined to memorize, add, and subtract a long table of numbers, there is a much simpler method available to the casual date-figure-outer, that involves minimal memorization and math-skills. Let's say you want to figure out what day of the week October 16th, 2006 falls on.

Step 1: figure out the date of the first Sunday of every month of the year in question — or if you really don't want to work, just figure out the date of the first Sunday for the month in question. Taking the former route, we see that the first Sundays of each month in 2006, going right from January, are as follows: 1 5 5 2 7 4 2 6 3 1 5 3*

Step 2: add or subtract. For instance, if our month was February, we would see that the first Sunday falls on the 5th, so if we wanted to figure out what day the 1st falls on, we would simply figure out what day comes five days before Sunday, which is Tuesday. Going back to our example, we can leap through the weeks by adding 7 until we get close enough to do this. Since the first Sunday of October falls on the 1st and we want to figure out what day the 16th falls on, we add 7 twice, taking us to Sunday the 15th. After that, we just add 1 to take us to the 16th, which means the 16th is a Monday. 1 + 7 + 7 + 1, and you're done.

The most difficult aspect of this method is being able to conjure up the month you want: interested noders are advised to learn the "peg system" provided in improve your memory, as it both improves recall and is rather fun. Most people, though, will only need this for dates in the immediate future, so that isn't much of a problem.

Of course, given the increasing prevalence of electronic calendars these days, one can simply take out one's cellphone, but this method provides the advantage that it

  1. Impresses people who don't know about it (or a more advanced version)
  2. Doesn't end up giving you brain cancer if you use it too much(1) and
  3. Won't be rendered useless by an EMP attack.

Source: Your Memory: How it Works and How to Improve it, by Kenneth L. Higby

*Grouping these by twos or threes is suggested for ease of memorisation.1. Pending the results of a scientific study.

Log in or register to write something here or to contact authors.