Skip to content

Instantly share code, notes, and snippets.

@carlynorama
Last active April 23, 2018 22:07
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 carlynorama/3fe8daf9d2e561ca5faca44fcf48298f to your computer and use it in GitHub Desktop.
Save carlynorama/3fe8daf9d2e561ca5faca44fcf48298f to your computer and use it in GitHub Desktop.
#code taken from example on
#https://stackoverflow.com/questions/2003870/how-can-i-select-all-of-the-sundays-for-a-year-using-python
from datetime import date, timedelta
dstart = date(2018,1,1)
dend = date(2018,12,31)
# this will return all sundays between start-end dates.
days = [dstart + timedelta(days=x) for x in range((dend-dstart).days + 1) if (dstart + timedelta(days=x)).weekday() == 1]
print len(days)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment