Skip to content

Instantly share code, notes, and snippets.

@taddeimania
Created March 25, 2016 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taddeimania/765fcc32fef6399eddd2 to your computer and use it in GitHub Desktop.
Save taddeimania/765fcc32fef6399eddd2 to your computer and use it in GitHub Desktop.
# Find day of the week in python 3
from enum import Enum
class DayOfWeek(Enum):
Sunday = 0
Monday = 1
Tuesday = 2
Wednesday = 3
Thursday = 4
Friday = 5
Saturday = 6
def get_day_of_week(year, month, day):
month_table = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
year -= 1 if month < 3 else 0
return DayOfWeek(int((year + year / 4 - year / 100 + year / 400 + month_table[month - 1] + day) % 7))
print(get_day_of_week(1990, 4, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment