0
$\begingroup$

I've been told there's a straightforward way to determine which day of the week a date falls on, by first using Gauss's algorithm, to find the day of the week of 1st of January. Then this can be combined with modulo 7 arithmetic on an ordinal day to calculate the day of the week for a particular date.

For example, Gauss's algorithm can tell us that, this year, the 1st of January fell on a Sunday, the 7th day of the week. Today is the 22nd of October, with an ordinal day of 295. How can this information be used to calculate that today is a Sunday?

$\endgroup$
  • $\begingroup$ Read Wikipedia article? $\endgroup$ – qwr Oct 22 '17 at 17:25
  • $\begingroup$ @qwr Which Wikipedia article are you referring to exactly? Does it use the approach I've mentioned or another one? $\endgroup$ – HumptyDumpty Oct 22 '17 at 17:45
  • $\begingroup$ To answer your actual question, take 295 mod 7 (the remainder when 295 is divided by 7), which is 1. The weekdays are numbered 0 - 6, with 0 being whatever weekday January 1 was on. so in this case, 1 corresponds to Monday. $\endgroup$ – Paul Sinclair Oct 22 '17 at 20:38
  • $\begingroup$ @PaulSinclair That would give an incorrect answer. 22nd of October, 2017 is a Sunday, which would have number 0. How about (ordinal day + day of 1st of January - 1) mod 7? e.g. (296 + 0 - 1) mod 7 = 0. $\endgroup$ – HumptyDumpty Oct 22 '17 at 21:05
  • $\begingroup$ Yeah. The ordinal day has Jan 1 as day 1, where this technique needs it to be day 0. So it should be: Weekday = (Ordinal day - 1) mod 7. And again, you need whatever weekday Jan 1 falls on to be 0, then go up from there. $\endgroup$ – Paul Sinclair Oct 22 '17 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.