How To Calculate The Weekday For Any Date
How To Calculate The Weekday For Any Date
http://5dspace-time.org/Calendar/Algorithm.html
How To Calculate The Weekday For Any Date On The Julian Or Gregorian Calendar
The following formula is used to calculate the weekday for any date on the calendar:
Since the offset for the century, the year, and the month all equal 0 for January 1900, we can forget about them for the present. We therefore only need to deal with the conversion of the day of the month to the weekday. Day Offset As the 1st day of this month falls on a Monday, let us assign Monday a value of 1. The 2nd day of the month has a value of 2, and as the day after Monday is Tuesday, we assign Tuesday the value of 2. In like manner, the first seven days of the month have the following values: Day Offsets Weekday Monday Tuesday Wednesday Numeric Value 1 2 3
1 of 9
25-12-2013 04:29
http://5dspace-time.org/Calendar/Algorithm.html
4 5 6 7
January 7 falls on day 7, and 7 corresponds to Sunday. On what day does January 8 fall? On any calendar you will notice that the 8th of any month falls on the same day as the 1st of the month, which falls on the same day as the 15th, the 22nd, and the 29th of the month. Therefore, if we subtract one week (7 days) from the January 8, we have January 1, which we know is a Monday. January 8 is therefore a Monday. This process of subtracting weeks from the 8th, 15th, 22nd, 29th etc. to achieve a number equal to or less than 7 is called modulo ("mod," for short). The word modulo is usually represented in computer languages as %. To find a number such as 20 % 7, divide 20 by 7, and keep only the remainder. 20 / 7 = 2 remainder 6. 20 % 7 = 6. The 20th falls on the same weekday as the 6th. (Please note that multiplication, which is usually indicated by an x in mathematics, as in 3 x 2 = 6, is usually indicated by an * in computer languages, as in 3 * 2 = 6. Multiplication will be indicated by an * here.) January 28 falls on 28 % 7 = 0. Which day of the week corresponds to 0? Sunday. We assigned Sunday a value of 7, but 7 % 7 = 0, and so we will modify the weekday values as follows: Day Offsets Weekday Sunday Monday Tuesday Wednesday Thursday Numeric Value 0 1 2 3 4
2 of 9
25-12-2013 04:29
http://5dspace-time.org/Calendar/Algorithm.html
Friday Saturday
5 6
We can now calculate the weekday for any date in January. Let us now calculate the month offsets. Month Offset January is the first month, and so we assigned January an offset of 0. January has 31 days. January 31 falls on 31 % 7 = 3 = Wednesday. Whenever January 1 falls on a Monday, February 1 falls on a Thursday, 3 days later. The February offset equals 0 (January offset) plus 31%7 = 3 (number of days in January). 0 + 3 = 3. Thus, for example, February 2 would fall on 3 (February offset) + 2 (Day offset) = 5 (Friday). February has 28 days (in a non leap year). 28 % 7 = 0. February 28 falls on 3 (February offset) + 0 (28 % 7) = 3 = Wednesday. Whenever February 1 falls on a Thursday, March 1 also falls on a Thursday, in a non leap year. The March offset equals 3 (February offset) plus 28%7 = 0 (number of days in February). 3 + 0 = 3. Thus, for example, March 12 would fall on 3 (March offset) + 12 (Day offset) = 15 % 7 = 1 (Monday). Month Offsets Month January February March April May June July August Offset 0 3 (0+3) 3 (3+0) 6 (3+3) 1 (6+2=8,%7) 4 (1+3) 6 (4+2) 2 (6+3=9, %7) Days 31 28 31 30 31 30 31 31 Days % 7 3 0 3 2 3 2 3 3 Add to next month's offset +3 +0 +3 +2 +3 +2 +3 +3
3 of 9
25-12-2013 04:29
http://5dspace-time.org/Calendar/Algorithm.html
30 31 30 31
2 3 2 3
+2 +3 +2 +3
The month offsets, which can easily be remembered to enable quick calculation of the weekday, are as follows: Month Offsets
Month Offset Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
Year Offset The month offset for December is 5. December has 31 days. 31%7=3. 5 (December offset) + 3 (number of days in December) = 8. 8%7=1. January, the month after December, has an offset of 1. Thus, if January 1 of one year falls on a Monday, and if it is not a leap year, then January 1 of the following year will fall on 365 % 7 = 1 (new year offset) + 0 (January offset) + 1 (Day offset) = 2 (Tuesday). Each year begins 1 day later in the week than the previous year, if the previous year is a non-leap year. The year 00, as in 1900, was previously assigned a year offset of 0. The year 1 would therefore have a year offset of 1. The year 2 would have a year offset of 2. The year 3 would have a year offset of 3. The year 4 begins with a year offset of 4. However, in a leap year February has 29 days. We accommodate this by adding 1 to the year offset in leap years. When calculating the weekday for a date in January or February of a leap year, we must subtract 1 from the year offset, as the leap day has not arrived yet. As every 4th year is a leap year, the year offset can be quickly calculated as Year + Year/4. (Remember that a year that ends in 00 is not a leap year in the Gregorian calendar unless it is also a multiple of 400.) Year Offsets Years 6, 17, 23, 28, 34, 45, 51, 56, 62, 73, 79, 84, 90 1, 7, 12, 18, 29, 35, 40, 46, 57, 63, 68, 74, 85, 91, 96 Offset 0 1
4 of 9
25-12-2013 04:29
http://5dspace-time.org/Calendar/Algorithm.html
2, 13, 19, 24, 30, 41, 47, 52, 58, 69, 75, 80, 86, 97 3, 8, 14, 25, 31, 36, 42, 53, 59, 64, 70, 81, 87, 92, 98 9, 15, 20, 26, 37, 43, 48, 54, 65, 71, 76, 82, 93, 99 4, 10, 21, 27, 32, 38, 49, 55, 60, 66, 77, 83, 88, 94 5, 11, 16, 22, 33, 39, 44, 50, 61, 67, 72, 78, 89, 95 Now, for some examples: January 1, 1999:
Century offset: 0 for 1900's Year offset: 99 + 99/4 = 99 + 24 = 123. 123%7 = 4 Month offset: 0 for January Day offset: 1 Weekday: 0 + 4 + 0 + 1 = 5 = Friday
2 3 4 5 6
February 14, 1920 fell on a Saturday. Century Offset (for the Gregorian Calendar) Each century has 100 years. 100 years has a total year offset of 100 + 100/4 = 125. 125%7 = 6. This calculation assumes 25 leap years in a century which, on the Gregorian calendar, is only true for centuries that are multiples of 400; i.e., 400, 800, 1200, 1600, 2000, etc. Thus, since 1900 has a century offset of 0, 2000 has a century offset of 6, and so begins one day earlier. Because the other 3 centuries out of every 4 do not have 25 leap years (the year 00 is not a leap year), they each have a total relative year offset of 124%7 = 5.
5 of 9 25-12-2013 04:29
http://5dspace-time.org/Calendar/Algorithm.html
1900 has a century offset of 0 (by our definition). 2000 has a century offset of 0 + 6 = 6 (0 + 125%7). 2100 has a century offset of 0 + 6 + 5 = 11 % 7 = 4 (0 + 6 + 124%7). 2200 has a century offset of 0 + 6 + 5 + 5 = 16 % 7 = 2 (0 + 6 + 5 + 124%7). The cycle is thus 0, 6, 4, 2, and it repeats every 400 years. Gregorian Century Offsets Century 300, 700, 1100, 1500,1900, etc. 400, 800, 1200, 1600, 2000, etc. 100, 500, 900, 1300, 1700, etc. 200, 600, 1000, 1400, 1800, etc. Offset 0 6 4 2
A shortcut to calculate the century offset for the Gregorian calendar is ((39 - Century) % 4) * 2. For example, the century offset for the 1200's would be ((39 - 12) % 4) * 2 = (27 % 4) * 2 = 3 * 2 = 6. The reason that 39 was selected here is that this calendar is valid only until the 3900s, and therefore 39 was selected as the next highest multiple of 4 (40) minus 1. The quickest way to determine the century offset for any given century is to find the next highest multiple of 4, subtract 1, subtract the desired century, and multiply the result by 2. For example, to find the century offset for the 1900s, the next highest multiple of 4 beyond 19 is 20. ((20 - 1) - 19) * 2 = 0, and 0 is the century offset for the 1900s. To find the century offset for the 2000s, the next highest multiple of 4 beyond 20 is 24. ((24 - 1) - 20) * 2 = 6. To find the century offset for the 7400s, the next highest multiple of 4 beyond 74 is 76. ((76 - 1) - 74) * 2 = 2. We now have all of the information required to calculate any date on the Gregorian calendar. We can do it quickly in our head or on a piece of paper if we can remember the 12 month offsets. Examples of dates on the Gregorian calendar July 4, 1776:
Century offset: ((20-1)-17)*2 = 4 Year offset: 76 + 76/4 = 76 + 19 = 95. 95%7 = 4 Month offset: 6 for July Day offset: 4 Weekday: 4 + 4 + 6 + 4 = 18. 18 % 7 = 4 = Thursday
6 of 9
25-12-2013 04:29
http://5dspace-time.org/Calendar/Algorithm.html
July 4, 1776 fell on a Thursday (on the Gregorian calendar). February 14, 2020:
Century offset: (((24-1)-20)*2 = 6 Year offset: 20 + 20/4 = 20 + 5 = 25. 25%7 = 4
(Subtract 1 because Jan/Feb of a leap year)
4-1=3
Month offset: 3 for February Day offset: 14. 14 % 7 = 0 Weekday: 6 + 3 + 3 + 0 = 12. 12 % 7 = 5 = Friday
February 14, 2020 will fall on a Friday (on the Gregorian calendar). Century Offset (for the Julian Calendar) To calculate dates on the Julian calendar is very similar to calculating dates for the Gregorian calendar. There are two differences. One is that the year 00 is always a leap year. Therefore, the years 1700, 1800, and 1900 are leap years. The other difference is that each century has a total of 100 years and 100/4 = 25 leap years. The relative century offset for the Julian calendar is always +6, as 125%7 = 6. For the Julian calendar, each century begins 1 day earlier then the previous century, with no exception every 4th century as for the Gregorian calendar. For the Julian calendar, the 1900s have a century offset of 6. The 1800s had an offset of 0. The 1700s had an offset of 1. And so on. From this trend two facts can be noted. One is that as the century increases, the century offset decreases. The other is that as the 1800s have an offset of 0, and as 18%7 = 4, 3 must be added to the century to make 4+3 = 7 and 7%7 = 0. Therefore, a quick method of calculating the century offset for the Julian calendar is to add 3 to the century and take the mod 7 (these two steps align the number with 0), and then subtract the result from 7 (to make the offset decrease as the century increases); i.e., 7 (Century + 3) % 7. Thus, the 1900s have a century offset of 7- (19+3) % 7 = 7 - 1 = 6. The 1800s have a century offset of 7 - (18+3) % 7 = 7 - 0 = 7, and 7%7 = 0. The 1000s have a century of 7 (10+3) % 7 = 7 - 6 = 1. The cycle is thus 6, 5, 4, 3, 2, 1, 0, and it repeats every 700 years. Julian Century Offsets Century Offset
7 of 9
25-12-2013 04:29
http://5dspace-time.org/Calendar/Algorithm.html
500, 1200, 1900, etc. 600, 1300, 2000, etc. 00, 700, 1400, etc. 100, 800, 1500, etc. 200, 900, 1600, etc. 300, 1000, 1700, etc. 400, 1100, 1800, etc.
6 5 4 3 2 1 0
We now have all of the information required to calculate any date on the Julian calendar. We can do it quickly in our head or on a piece of paper if we can remember the 12 month offsets. Examples of dates on the Julian calendar July 4, 1776:
Century offset: 7 - (17 + 3) % 7 = 1 Year offset: 76 + 76/4 = 76 + 19 = 95. 95%7 = 4 Month offset: 6 for July Day offset: 4 Weekday: 1 + 4 + 6 + 4 = 15. 15 % 7 = 1 = Monday
July 4, 1776 fell on a Monday (on the Julian calendar). February 14, 2020:
Century offset: 7 - (20 + 3) % 7 = 5 Year offset: 20 + 20/4 = 20 + 5 = 25. 25%7 = 4
(Subtract 1 because Jan/Feb of a leap year)
4-1=3
Month offset: 3 for February Day offset: 14. 14 % 7 = 0 Weekday: 5 + 3 + 3 + 0 = 11. 11 % 7 = 4 = Thursday
February 14, 2020 will fall on a Thursday (on the Julian calendar.) Conclusion The algorithm for calculating the dates on the calendar is surprisingly simple. It is so
8 of 9 25-12-2013 04:29
http://5dspace-time.org/Calendar/Algorithm.html
simple that with minimum practice, and memorizing the 12 month offsets, it can be done in the head or on paper. The algorithm is also very simple for a computer to calculate, as is demonstrated by this calendar program.
9 of 9
25-12-2013 04:29