Skip to content

Instantly share code, notes, and snippets.

@casimir
Created January 18, 2017 10:38
Show Gist options
  • Save casimir/36bfd01bf070877895dfc23536a1ca15 to your computer and use it in GitHub Desktop.
Save casimir/36bfd01bf070877895dfc23536a1ca15 to your computer and use it in GitHub Desktop.
A whole new year
import datetime as dt
def last_month():
last_eom = dt.date.today().replace(day=1) - dt.timedelta(days=1)
to_date = last_eom + dt.timedelta(days=1)
from_date = last_eom.replace(day=1)
return from_date, to_date
# >>> print(dt.date.today())
# 2017-01-18
# >>> fdate, tdate = last_month()
# >>> print(fdate)
# 2016-12-01
# >>> print(tdate)
# 2017-01-01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment