Change the date_range function to count the difference between end and start and then loop a list of all dates in that range def date_range(start_date, end_date): lst = [] if start_date > end_date: return [] else: try: start = (dt.strptime(start_date, '%Y-%m-%d')) end = (dt.strptime(end_date, '%Y-%m-%d')) lst.append(start.strftime('%Y-%m-%d')) start += td(days=1) return lst except: return [] Examples: Input: date_range('2022-12-01', '2022-12-05') Output: ['2022-12-01', '2022-12-02', '2022-12-03', '2022-12-04', '2022-12-05']
from datetime import date, timedelta as td def date_range(start_date, end_date): lst = [] if start_date > end_date: return [] else: try: start = (dt.strptime(start_date, '%Y-%m-%d')) end = (dt.strptime(end_date, '%Y-%m-%d')) while start <= end: lst.append(start.strftime('%Y-%m-%d')) start += td(days=1) return lst except: return []