Creates a list of dates between start
(inclusive) and end
(not inclusive).
datetime.timedelta.days
to get the days between start
and end
.int()
to convert the result to an integer and range()
to iterate over each day.datetime.timedelta
to create a list of datetime.date
objects.from datetime import timedelta, date
def daterange(start, end):
return [start + timedelta(n) for n in range(int((end - start).days))]
from datetime import date
daterange(date(2020, 10, 1), date(2020, 10, 5))
# [date(2020, 10, 1), date(2020, 10, 2), date(2020, 10, 3), date(2020, 10, 4)]
Python, Date
Calculates the month difference between two dates.
Python, Date
Calculates the day difference between two dates.
Python, Date
Checks if the given date is a weekend.