Tuesday 10 November 2015

Day of the week from ANY date

Hi guys, welcome to Orygyn!

Want a good party trick and don't mind it being a bit geeky? Learn to work out the day of the week from any date in history in seconds (with maybe a few hours practice once you know the system).

My job gets quite repetitive sometimes. To deal with this, I find ways to pass the time and, since my maths degree isn't really being used at my current job, I thought I'd find a way to squeeze it in there. I see birth dates all the time, so one easy thing to occupy some time is to work out the day of the week. Well, I worked out a system for doing it.

Before I go any further, let me just say that I'm not saying I invented it. There are systems out there. It's possible someone came up with the same system and I'm not even going to claim this is the best. I just worked this one out. Anyway:

Let's take an arbitrary date: 15/09/1990 (day/month/year).

Step 1: Work out a small number (0-6) for the day (15/xx/xxxx).

To do this, you take the day, divide it by 7, and your "day number" is the remainder. If you're not great at dividing, just keep subtracting 7 until you have a number under 7. If do this a lot, you'll eventually memorize them all.

The result in the example is 1: 15 divided by 7 is 2 remainder 1, or subtracting 7 gives you 8, then doing it again gives you 1.

Step 2: Work out a small number (0-6) for the month (xx/09/xxxx).

Americans and others who follow month/day/year will probably do this step first then step 1. The best way to get the month number is to simply memorize them but I will explain how I derived this system at the end for anyone who's interested.

January - 0
February - 3
March - 3
April - 6
May - 1
June - 4
July - 6
August - 2
September - 5
October - 0
November - 3
December - 5

09 is of course September so the month number here is 5.

Step 3: Work out a small number (0-6) for the year (xx/xx/1990).

This is the most difficult step. First, you need to memorize a few reference years. I will write down all the ones for the 20th and 21st centuries:

1888 (included to deal with years from 1900-1915)
1916
1944
1972
2000
2028
2056
2084

It's no coincidence that these years are 28 years apart, and to find a reference number for a year earlier than this, you simply need to keep going forward or backward in jumps of 28. All of these reference years have a "year number" of 0.

To work out the year number for any other year, take the reference year immediately before your date and start counting up until you get to the year in your date. Add 1 to your year number for each normal year and 2 for every 4 years. Once you have your result, divide the answer by 7 again, and take the remainder.

For 1990, the reference year immediately before this is 1972. There are 18 years between the 2 dates, 4 goes into 18 4 times, so you end up with 22. Dividing this by 7 gives you 3 remainder 1.

You may complain that this is a hopelessly slow and/or complicated step, and you'd be right. It's easier, once again, to just memorize the year numbers, I included the complicated way above so that you know how to find the year number if you forget it:

Years removed from reference year - Year number
1 - 1
2 - 2
3 - 3
4 - 5
5 - 6
6 - 0
7 - 1
8 - 3
9 - 4
10 - 5
11 - 6
12 - 1
13 - 2
14 - 3
15 - 4
16 - 6
17 - 0
18 - 1
19 - 2
20 - 4
21 - 5
22 - 6
23 - 0
24 - 2
25 - 3
26 - 4
27 - 5

Step 4: Add up your total. There are 2 final steps that apply under certain conditions:

a) If your date is in January or February of a leap year, subtract 1.
b) A not-so-well known fact about dates is that centenary years (1700, 1800 etc.) are NOT leap years unless they are divisible by 400. To account for this, when going backwards through the centuries, add 1 for each centenary non-leap year, and when going forwards, subtract 1.

Neither of these additional conditions applies to our example date. So, what do we get?

1 + 5 + 1 = 7

To find the day:
-1 - Friday
0 - Saturday
1 - Sunday
2 - Monday
3 - Tuesday
4 - Wednesday
5 - Thursday
6 - Friday
7 - Saturday
8 - Sunday
9 - Monday
10 - Tuesday
11 - Wednesday
12 - Thursday
13 - Friday
14 - Saturday
15 - Sunday
16 - Monday
17 - Tuesday
18 - Wednesday

So 15/09/1990 is a Saturday!

So how effective is this technique? If you're working out all the steps the first time round, it will probably take about a minute, but it depends on your maths abilities. This is why I advise memorizing them, as it is much quicker. I can do any date this century or last in about 5 seconds now. It requires very little effort. Sometimes I forget to subtract 1 for the Jan/Feb leap year dates, and that's mostly because they're quite rare, but for the most part, that is a taste of what you could do. Know the steps inside out and I reckon, within an hour or two, you could be at the 10 second level. From there, it's diminishing returns, as you need to relentlessly focus on which steps are tripping you up.

For a lot of people, this is where we part ways. However, if you want to know how I derived my system, read on :)



OK so to start with, I looked up the day of the week for January 1st 2000. I thought it'd be as good a place as any to start. Turns out it's a Saturday. Trivially, each 7 day jump after that will also be a Saturday. What about February 1st 2000? This is a Tuesday. There is a distance of 31 days between these 2 dates and this amounts to 3 days of the week. This makes sense. A week is 7 days, there are 4 full weeks in 31 days, and then 3 extra days left over. This gives us the beginning of the method to derive the month number: take the number of days in that month, divide it by 7, take the remainder, and add it to the month number of the last month.

This isn't the whole story though. Take March 1st 2000, a Wednesday (1 + 3 + 0 = 4). 2000 is a leap year, and so there are 29 days in February in that year. The problem then is that, in most years, February 1st and March 1st would be on the same day of the week (28 divides EXACTLY by 7), but on leap years, March 1st will be a day of the week later. This gives us condition a) from earlier, and also the reason why, when it comes to year numbers, you add 2 for every 4th year you pass. As each reference year is a leap year (28 is a multiple of 4 and 2000 is a leap year), each 4th year is a leap year.

This allows us to assign arbitrary values to January 1st 2000: keeping the day number as is, just simplifying it to below 0-6 (by dividing by 7 and taking the remainder) keeps it very simple: 1st = 1. We are subtracting 1 because it's January of a leap year: 1-1=0. January is the first month so why make it anything other than 0? 2000 is a leap year, and a year familiar to most of us, so again why not 0. Without having to figure anything else out, we've assigned a final number of 0 to Saturday. To work out all other final numbers, we simply recognize that you can't get a number lower than -1 (January 7th 2000 = 0 + 0 + 0 -1 = -1) or higher than 18 (April 6th 2005 = 6 + 6 + 6), and count them along with the days of the week, repeating the cycle after each 7. I tend to keep the final number under 7 as well so I apply century adjustments after.

This leaves the year number and condition b). The year number is derived as simply as this: 365 days in a year. 365 divided by 7 is 52 remainder 1. 366 divided by 7 is 52 remainder 2. This gives us the 1 and 2 we repeatedly add to get the year number. As this number is kept between 0 and 6 (a range of 7 numbers), and adding 2 happens every 4 numbers, this cycle will repeat every 28 years (7 x 4 = 28) giving us the motivation behind reference numbers.

Finally, to derive condition b), take March 1st 1900, a Thursday (1 + 3 + 1 = 5). As 1900 is not a leap year (it does not divide exactly by 400), March 1st immediately follows February 28th, a Wednesday. In 1928, which is a leap year, February 29th would be the Wednesday and so February 28th would be a Tuesday. February 28th is 1 day of the week later in 1900 than it would otherwise be, and then so is every date for the 100 years including and immediately before Feb 28th 1900. This means we add 1 to bring our system into alignment. Using the exact same logic, we subtract 1 when going in the opposite direction.

And we are done! Thanks for reading.

8<{D-

No comments:

Post a Comment