alt text

Calendar Algorithm for any date in the 20th or 21st century

Note that January 1, 1901 was Tuesday and January 1, 2001 was Monday

In [1]:
def calculate_day(year,month,day): 
    
    if month==1: shift=0
    elif month==2: shift=3
    elif month==3: shift=3
    elif month==4: shift=6
    elif month==5: shift=1
    elif month==6: shift=4
    elif month==7: shift=6
    elif month==8: shift=2
    elif month==9: shift=5
    elif month==10: shift=0
    elif month==11: shift=3
    elif month==12: shift=5
    else: return "ERROR" 
        
    mytotal=(year-1900) + (year-1900)//4 + day + shift
    
    if month<=2 and year%4==0: mytotal=mytotal-1
    
    remainder = mytotal % 7
    
    if remainder==0: return "Sunday"
    elif remainder==1: return "Monday"
    elif remainder==2: return "Tuesday"
    elif remainder==3: return "Wednesday"
    elif remainder==4: return "Thursday"
    elif remainder==5: return "Friday"
    elif remainder==6: return "Saturday"
    else: return "ERROR"
In [3]:
calculate_day(2019,1,11)
Out[3]:
'Friday'
In [5]:
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets

interact(calculate_day, year=widgets.IntSlider(min=1900, max=2019, step=1, value=1950), month=widgets.IntSlider(min=1, max=12, step=1, value=1), day=widgets.IntSlider(min=1, max=31, step=1, value=1))
Out[5]:
<function __main__.calculate_day(year, month, day)>

alt text