Skip to content

Instantly share code, notes, and snippets.

@maxcraftsman
Created July 20, 2020 04:54
Show Gist options
  • Save maxcraftsman/89fb98041da1fee961d415ba971d9929 to your computer and use it in GitHub Desktop.
Save maxcraftsman/89fb98041da1fee961d415ba971d9929 to your computer and use it in GitHub Desktop.
Date array generator
from datetime import date, datetime, timedelta
from calendar import monthrange
import pytz
dateRange = []
curTime = datetime.now()
def generateRange(start,end):
for y in range(start,end):
for m in range(1,13):
datestr = '{}-{}-{}'.format(y,m,monthrange(y, m)[1])
dateformat = datetime.strptime(datestr, "%Y-%m-%d")
if dateformat < curTime:
dateRange.append(datestr)
generateRange(2020,2021)
print(dateRange)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment