I have some code that returns the last day of every month in 2017.
Results:
2017-01-31
2017-02-28
2017-03-31
2017-04-30
2017-05-31
2017-06-30
2017-07-31
2017-08-31
2017-09-30
2017-10-31
2017-11-30
2017-12-31
However, I would like to make it include the years 2014 through 2017 and not just 2017. I have not been able to find anything online that would accomplish this and have not been able to figure it out myself. All help/advice would be much appreciated.
Here is my code:
import arcpy
import datetime
from datetime import timedelta
import time
import calendar
#returns last day of each month
def lastdayofmonth(anyday):
nextmonth = anyday.replace(day=28) + datetime.timedelta(days=4)
return next_month - datetime.timedelta(days=nextmonth.day)
for month in range(1, 13):
print (lastdayofmonth(datetime.date(2017, month, 1)))