Answers for "get a list of dates between two dates using python"

3

python get dates between two dates

from datetime import datetime, timedelta

def date_range(start, end):
    delta = end - start  # as timedelta
    days = [start + timedelta(days=i) for i in range(delta.days + 1)]
    return days

start_date = datetime(2008, 8, 1)
end_date = datetime(2008, 8, 3)
    
print(date_range(start_date, end_date))
Posted by: Guest on September-09-2020
0

Get a list of dates between two dates

from datetime import timedelta, date

def daterange(date1, date2):
    for n in range(int ((date2 - date1).days)+1):
        yield date1 + timedelta(n)

start_dt = date(2015, 12, 20)
end_dt = date(2016, 1, 11)
for dt in daterange(start_dt, end_dt):
    print(dt.strftime("%Y-%m-%d"))
Posted by: Guest on July-21-2021

Code answers related to "get a list of dates between two dates using python"

Python Answers by Framework

Browse Popular Code Answers by Language