Skip to content

Instantly share code, notes, and snippets.

@Shih-Po
Last active August 4, 2017 02:32
Show Gist options
  • Select an option

  • Save Shih-Po/92c044627ddb766d90d95bc0e34f207a to your computer and use it in GitHub Desktop.

Select an option

Save Shih-Po/92c044627ddb766d90d95bc0e34f207a to your computer and use it in GitHub Desktop.
from datetime import datetime, timedelta
def get_last_month_datetime(now):
return now.replace(day=1) - timedelta(days=1)
now = datetime.now()
last_month_datetime = get_last_month_datetime(now)
print(last_month_datetime)
before_last_month_datetime = get_last_month_datetime(
get_last_month_datetime(now)
)
print(before_last_month_datetime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment