How the day of week is calculated
The most reliable method is Zeller's congruence or the Tomohiko Sakamoto algorithm, both of which use modular arithmetic to map any Gregorian calendar date to a day of the week without needing to consult a calendar. The formula accounts for the irregular lengths of months and the 400-year Gregorian leap year cycle.
The day of year is calculated by summing the days in each preceding month (using the correct February length for leap years) and adding the day of the month. The ISO week number follows the ISO 8601 standard: week 1 is the week containing the first Thursday of the year, and weeks run Monday to Sunday.
Day of week = (day + floor(2.6 × month − 0.2) + year + floor(year/4) + floor(century/4) − 2 × century) mod 7
Zeller's congruence (Gregorian); result 0=Sunday … 6=Saturday.
Day of year = Sum of days in Jan through (month−1) + day (+ 1 if after Feb in a leap year)
Returns a value from 1 (1 Jan) to 365 or 366 (31 Dec).