Reputation: 37
import datetime
startDate = '2020-01-01'
start = datetime.datetime.strptime(startDate, '%Y-%m-%d')
holidays=[2020-1-5, 2020-1-11, 2020-1-13]
for dayNum in range(0,366):
dayOfYear = start + datetime.timedelta(days=dayNum)
if dayNum in holidays:
print("HOLIDAY")
Upvotes: 0
Views: 38
Reputation: 1085
import datetime
startDate = '2020-01-01'
start = datetime.datetime.strptime(startDate, '%Y-%m-%d')
holidays=["2020-01-01", "2020-01-03", "2020-01-05"]
for dayNum in range(0,366):
dayOfYear = start + datetime.timedelta(days=dayNum)
if str(dayOfYear).split(" ")[0] in holidays:
print(str(dayOfYear).split(" ")[0]+" is HOLIDAY")
try this
Upvotes: 0
Reputation: 178
Something like this should work
from datetime import datetime, timedelta
startDate = '2020-01-01'
start = datetime.strptime(startDate, '%Y-%m-%d')
holidays_str = ['2020-01-05', '2020-01-11', '2020-01-13']
holidays = [datetime.strptime(day, '%Y-%m-%d') for day in holidays_str]
for day in range(0, 366):
day_of_year = start + timedelta(days=day)
if day_of_year in holidays:
print(datetime.strftime(day_of_year, '%Y-%m-%d'), "HOLIDAY")
Upvotes: 1