Day of a year: it is calculated by following formula:
day = (year + [year/4] - [year/100] + [year/400] + [month code] + [day code]) mod 7
Where:
- "year" represents the year for which you want to find the day.
- "[year/4]" represents the integer division of the year by 4.
- "[year/100]" represents the integer division of the year by 100.
- "[year/400]" represents the integer division of the year by 400.
- "[month code]" represents a code for each month, as follows:
- January = 1, February = 4, March = 4, April = 0, May = 2, June = 5, July = 0, August = 3, September = 6,
October = 1, November = 4, December = 6
- "[day code]" represents the day of the month for which you want to find the day, as follows:
- Sunday = 0, Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6
Note: If the year is a leap year, the month code for January and February should be decreased by 1. If
the year is not a leap year, the month code for March to December should be decreased by 1.
Example:
To find the day of January 1st, 2021:
day = (2021 + [2021/4] - [2021/100] + [2021/400] + 1 + 0) mod 7
day = (2021 + 505 - 20 + 5 + 1) mod 7
day = (2511) mod 7
day = 2
Therefore, January 1st, 2021 falls on a Friday.
day = (year + [year/4] - [year/100] + [year/400] + [month code] + [day code]) mod 7
Where:
- "year" represents the year for which you want to find the day.
- "[year/4]" represents the integer division of the year by 4.
- "[year/100]" represents the integer division of the year by 100.
- "[year/400]" represents the integer division of the year by 400.
- "[month code]" represents a code for each month, as follows:
- January = 1, February = 4, March = 4, April = 0, May = 2, June = 5, July = 0, August = 3, September = 6,
October = 1, November = 4, December = 6
- "[day code]" represents the day of the month for which you want to find the day, as follows:
- Sunday = 0, Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6
Note: If the year is a leap year, the month code for January and February should be decreased by 1. If
the year is not a leap year, the month code for March to December should be decreased by 1.
Example:
To find the day of January 1st, 2021:
day = (2021 + [2021/4] - [2021/100] + [2021/400] + 1 + 0) mod 7
day = (2021 + 505 - 20 + 5 + 1) mod 7
day = (2511) mod 7
day = 2
Therefore, January 1st, 2021 falls on a Friday.