4 ms·
Memorize this table of offsets: 0 Oct, Jan 1 May 2 Aug 3 Feb, Mar, Nov 4 Jun 5 Sep, Dec 6 Apr, Jul Precalculate the offset for the year (2017 is
by pklausler 10y ago
Memorize this table of offsets:
0 Oct, Jan
1 May
2 Aug
3 Feb, Mar, Nov
4 Jun
5 Sep, Dec
6 Apr, Jul
Precalculate the offset for the year (2017 is 117 + trunc(117/4) == 146 == 6 mod 7). Then the day of the week for, say, today, is 6 (for the year) + 3 (for Feb) + 23 (day of the month) == 32 == 4 mod 7, which is Thursday .
Other examples: D-Day, 6 June 1944, was (44+11 == 55 == 6 mod 7 for the year) + 4 (Jun) + 6 == 16 == 2 mod 7 == Tuesday.
The only twist is needing to subtract 1 from the result for dates in Jan and Feb on leap years, since those dates precede the leap day.
- pmoriarty 10y agoI don't understand how you got the "6 mod 7" in the two examples above. Everything else makes sense, though. Thanks.