Skip to content

Instantly share code, notes, and snippets.

@altbdoor
Last active April 26, 2018 10:39
Show Gist options
  • Save altbdoor/a9b7de505416c1056ffb635687b22746 to your computer and use it in GitHub Desktop.
Save altbdoor/a9b7de505416c1056ffb635687b22746 to your computer and use it in GitHub Desktop.
Some odd day to day implementation for a certain client on some date calculation stuff
#!/bin/usr/env python
import calendar
import datetime
max_month = 5
start_date = datetime.datetime(2018, 2, 28)
copy_start_date = start_date
print(copy_start_date)
for i in range(1, (max_month + 1)):
copy_start_date = copy_start_date.replace(day=1).replace(month=copy_start_date.month + 1)
try:
copy_start_date = copy_start_date.replace(day=start_date.day)
except:
days_range = calendar.monthrange(copy_start_date.year, copy_start_date.month)
copy_start_date = copy_start_date.replace(day=days_range[1])
print(copy_start_date)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment