Skip to content

Instantly share code, notes, and snippets.

@tsileo
Created April 11, 2013 16:04
Show Gist options
  • Save tsileo/5364680 to your computer and use it in GitHub Desktop.
Save tsileo/5364680 to your computer and use it in GitHub Desktop.
Return the last x days from a datetime.date object
from dateutil.relativedelta import relativedelta
from datetime import date
def get_last_x_days(x, date_from=date.today()):
for i in xrange(x):
date_from += relativedelta(days=i)
yield date_from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment