Calculating which day of the week a date falls on using Gauss's algorithm and modulo arithmetic

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?

• Read Wikipedia article? – qwr Oct 22 '17 at 17:25
• @qwr Which Wikipedia article are you referring to exactly? Does it use the approach I've mentioned or another one? – HumptyDumpty Oct 22 '17 at 17:45
• 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. – Paul Sinclair Oct 22 '17 at 20:38
• @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. – HumptyDumpty Oct 22 '17 at 21:05
• 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. – Paul Sinclair Oct 22 '17 at 22:08