Skip to content

Instantly share code, notes, and snippets.

@yurivictor
Created April 13, 2012 22:57
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 yurivictor/2380671 to your computer and use it in GitHub Desktop.
Save yurivictor/2380671 to your computer and use it in GitHub Desktop.
Get the number of Friday the 13ths in the past 100 years
from datetime import *
from dateutil.rrule import *
from dateutil.relativedelta import *
def get_friday_the_13s():
YEARS_AGO = 100
TODAY = date.today()
YEARSAGO = TODAY + relativedelta(years=-YEARS_AGO)
fridays = list(rrule(DAILY, byweekday=(FR), dtstart=YEARSAGO, until=TODAY))
friday13s = list(rrule(DAILY, bymonthday=13, byweekday=(FR), dtstart=YEARSAGO, until=TODAY))
print 'In the past', YEARS_AGO, 'years, there have been', len(friday13s), 'Friday the 13ths.'
get_friday_the_13s()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment